If you want repeated whitespaces to be ignored, then simply tell split to do so.
DB<113> split ' ', 'abc def' => ("abc", "def") DB<114> $del=qr/ / => qr/ / DB<115> split $del, 'abc def' => ("abc", "", "def") DB<116> $del=qr/\s+/ => qr/\s+/ DB<117> split $del, 'abc def' => ("abc", "def")
Cheers Rolf
( addicted to the Perl Programming Language)
split :
As a special case, specifying a PATTERN of space (' ') +will split on white space just as "split" with no arguments +does. Thus, "split(' ')" can be used to emulate awk’s default behavior, whereas "split(/ /)" will give you as many nu +ll initial fields as there are leading spaces. A "split" +on "/\s+/" is like a "split(' ')" except that any leading whitespace produces a null first field. A "split" with + no arguments really does a "split(' ', $_)" internally.
In reply to Re: How to get split $var to work like split ' '?
by LanX
in thread How to get split $var to work like split ' '?
by QM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |