.------[ Michael Weber wrote (2003/03/25 at 13:23:36) ]------ | | 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? | `-------------------------------------------------
split() doesn't just take a character as to what to separate on, it takes a regular expression. What you're running into is that the period means "any character" in a regular expression. So if you did the following it would work as expected: perl -e '@NEW = split(/\./, "1.2.3"); print "x", $NEW[1], "x\n"; ' The forward slashes denote the start/end of the pattern and the backslash says to use a literal period as opposed to the regex operator 'any character'. Hope this helps. --------------------------------- Frank Wiles <[EMAIL PROTECTED]> http://frank.wiles.org --------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]