in reply to Re: How to get split $var to work like split ' '?
in thread How to get split $var to work like split ' '?
I'd like the split ' ' behavior, unless changed from the command line option. Something like this:
my $split_pattern = ' '; # default ... # $split_pattern might get changed here from a command line option $split_pattern = $foo if $bar; ... $line = " one two three \n"; my @words = split $split_pattern, $line; for my $i (0..$#words) { print "$i: ($words[$i])\n"; } # Expected output for default case 0: one 1: two 2: three # Actual output for default case 0: () 1: () 2: () 3: (one) 4: (two) 5: (three) 6: () 7: () 8: ( )
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How to get split $var to work like split ' '?
by Laurent_R (Canon) on Sep 10, 2013 at 17:19 UTC |
In Section
Seekers of Perl Wisdom