more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Well, yeah, split uses /\s+/
by default - sort of. However, the first argument, if any,
of split is the regular expression. Only if
the first argument is missing, it results to the default.
In your example, which of course you haven't tested, you
give split one argument. One argument split
will split $_, using the regular expression
given - in your case, the value of $line.
Which is not at all what you want.
I said "sort of", meaning that the default case (that is, no arguments to split) trailing empty fields are removed - just like in awk. Which doesn't happen if you use /\s+/ as first argument. Use ' ' to get the effect of the default behaviour. You know, you would have saved a lot of trouble, from both you and me (and people who thought you spoke the truth and used your suggestion) if you had either tried out your suggestion or had consulted the manual page. But I guess a quick typing without thinking is the fast lane to fame. -- Abigail In reply to Re: Splitting each word in a string
by Abigail
|
|