Perl: split string

Perl: split string

Post by Dmit » Tue, 08 Oct 2002 21:25:14



Hi all

I have a string that should be split to array of lines according to the following:
   - newline donates end of the current line
   - each line should be not longer than 5 characters and line can
     split a word

Assume that there is no words longer than 5 characters

E.g. String "abc\n12 45678"
     Line[0] = "abc"
     Line[2] = "12 "
     Line[3] ="45678";

Thanks

 
 
 

Perl: split string

Post by Barry Margoli » Wed, 09 Oct 2002 02:59:17




>I have a string that should be split to array of lines according to the
>following:
>   - newline donates end of the current line
>   - each line should be not longer than 5 characters and line can
>     split a word

>Assume that there is no words longer than 5 characters

>E.g. String "abc\n12 45678"
>     Line[0] = "abc"
>     Line[2] = "12 "
>     Line[3] ="45678";

This example doesn't seem to match your description.  What happened to
line[1], and why is line[2] only 3 characters long instead of 5 characters?
Could you describe better what you're trying to do?

BTW, why aren't you asking this question in a Perl newsgroup?  The string
functions in Perl are hardly Unix-specific.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. splitting up a four character string into single chars

Hello,

I read in a zone code into one of my scripts; these codes are always
4 characters in length. I then need to split the string up into single
characters, to do furhter processing work.
This is where I am stuck, I can get the length of string OK, ( as a
check), but I cannot seem to assign each character to a var inside
a loop.

any ideas please
Peter.

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Printing without a banner

3. Howto split a string

4. No pppd lock file, then Failure

5. Help W/Unix Shell Script - File Splitting Based on Text String

6. Solaris upgrade from 2.5 to 2.6

7. Howto Split a string in single vars

8. Coverting server scripts into html new elements

9. nawk question, split string

10. splitting strings with delimiters

11. how to split a string?

12. Splitting strings

13. Splitting up string into different variables