in reply to split trying to look for /

You could escape the back-slash, or more readably, pass it in using an alternate delimiter, or simpler still, as a string e.g
my @date = split '/', '16/12/2003'; print "Day = $date[0]\n"; print "Month = $date[1]\n"; print "Year = $date[2]\n"; __output__ Day = 16 Month = 12 Year = 2003
And you'll also want to be using a scalar as a second argument to split, not an array.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: split trying to look for /
by duff (Parson) on Dec 16, 2003 at 15:38 UTC
    You could escape the back-slash, or more readably, pass it in using an alternate delimiter, or simpler still, as a string

    Actually, that's not a string; it's a regular expression with single quote delimiters. The first argument to split() is always a regular expression except in the one special case of ' '. Try splitting on '*' sometime. :-)

      The first argument to split() is always a regular expression

      Has this always been true? I remember a time long ago when I tried to use split "\n", "foo\nbar"; and got an error stating that using double quotes to split on a newline was wrong and that split /\n/, "foo\nbar"; should be used. I just tried a one-liner with warnings and strict enabled and did not get that same warning/error. Would you know why using double quotes used to give funny results?

        I have never seen nor heard of such behavior before, so I can't answer that. However, as to whether it's always been true that the first arg to split() is always a regular expression ... it's been true at least since perl 4 :-)