in reply to Difficulties with split

my 2 cents...

#!/usr/bin/perl use warnings; $in = $ARGV[0]; @vals = split(/\.\./, $in); print @vals;

perliff

----------------------

"with perl on my side"

Replies are listed 'Best First'.
Re^2: Difficulties with split
by johngg (Canon) on Apr 28, 2009 at 22:12 UTC

    A full stop is a regular expression metacharacter meaning match any character (with caveats, see perlretut, perlre). However, a backslash escapes the special meaning of a metacharacter so that \. matches a literal full stop. That means you are spliting on two literal full stops, which is not quite what was wanted.

    $ perl -le ' > $in = q{abcdefg}; > @vals = split m{\.\.}, $in; > print for @vals;' abcdefg $ perl -le ' > $in = q{abc..defg}; > @vals = split m{\.\.}, $in; > print for @vals;' abc defg $

    I hope this is of interest.

    Cheers,

    JohnGG