Yes, that occurred to me later.

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


In reply to Re^2: How to get split $var to work like split ' '? by QM
in thread How to get split $var to work like split ' '? by QM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.