in reply to Re: How to get split $var to work like split ' '?
in thread How to get split $var to work like split ' '?
Still, to follow the Principle of Least Astonishment, I'd like to be able to specify a regex. To avoid further if then's, I'd probably set the default like so:
my $sep = q/' '/; $sep = shift @ARGV if @ARGV; # you get the idea my $line = " one two three \n"; my @words = eval qq(split $sep, \$line);
Then something evaluating to a regex must be used, such as:
$sep = q(/\s+/); $sep = q(//); $sep = q(/two|\s+/); $sep = q(m|/|);
But the delimiters must be part of the string.
(I'm ignoring for now the security issue of letting the user specify a regex, as this is a script just for me. And I'm not up to untainting the full regex language, so I can't see letting this into the wild hands of colleagues.)
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|