in reply to How to get split $var to work like split ' '?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get split $var to work like split ' '?
by QM (Parson) on Sep 10, 2013 at 16:31 UTC | |
by Laurent_R (Canon) on Sep 10, 2013 at 17:19 UTC | |
|
Re^2: How to get split $var to work like split ' '?
by hdb (Monsignor) on Sep 10, 2013 at 20:30 UTC |