Michael Weber wrote:

> Here are two scripts, the only difference is the marker I am splitting
> by.  I really expect the output from the two scripts to be the same.
> Why is the output different?
>
> perl -e '@NEW = split(".", "1.2.3"); print "x", $NEW[1], "x\n"; '
> Outputs  xx
>
> perl -e '@NEW = split("_", "1_2_3"); print "x", $NEW[1], "x\n"; '
> Outputs  x2x
>
> Can't I use a period to mark fields in perl?

Commas are better, they are a standard in database echange.  Theproblem here is more 
general, though.  The split function uses regular expressions, rather than strings, to 
split on.  This worked at all because the interpreter assumed you were using '"' as an 
alternative delimiter instead of '/'.  You would have gotten the smae results for:

perl -e '@NEW = split(#.#, "1.2.3"); print "x", $NEW[1], "x\n"; '

Perl is very flexible this way, and sometimes just bloody confuising also.  Try:

perl -e '@numerals = split(/\./, "1.2.3"); print "x", $numerals[1], "x\n"; '

and see what you get.

joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to