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...
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'.)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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |