in reply to How to get split $var to work like split ' '?
You'll need to use an if statement:
my $split_pattern //= getOpt(); my @x; unless( defined $split_pattern ) { @x = split ' ', $line; } else @x = split $split_pattern, $line; }
Not elegant, but the only way. The special behaviour of split ' ', is triggered by the use of exactly ' ' in the source code.
Substituting a variable set to a space, or even a conditional statement where one branch is ' ', will not do the same thing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get split $var to work like split ' '?
by hdb (Monsignor) on Sep 10, 2013 at 20:19 UTC | |
by brianski (Novice) on Sep 11, 2013 at 00:24 UTC | |
by brianski (Novice) on Sep 11, 2013 at 00:19 UTC |