You say:
You should pass a pattern as its first argument, but instead you're passing a scalar.

Yes, split does expect a pattern. But no, it does not have to be delimited with forward slashes. In fact, Perl doesn't even require delimiters here. A scalar value in a variable will be interpreted as a pattern also. Either of the following cases works fine...

my $str = 'this_is_a_group_of_words'; my @ary = split "_", $str; print "[$_]\n" for @ary; my $str = 'this_is_a_group_of_words'; my $pat = '_'; my @ary = split $pat, $str; print "[$_]\n" for @ary;
perldoc -f split says "The pattern "/PATTERN/" may be replaced with an expression to specify patterns that vary at run-time." but then confuses things by going on with, "(To do runtime compilation only once, use "/$variable/o".)" which makes it look like you still need the slashes. (Which you do if you want to add the '/o'.)

Camel 3, page 796, is more clear on this point when it says "if you supply a string instead of a regular expression, it will be interpreted as a regular expression anyway."

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall


In reply to Re: Re: spaces in filenames by dvergin
in thread spaces in filenames by ironpaw

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.