Note that there are *three* magical features happening. First there's the magic of the first argument; if the first argument of split is a pattern consisting of a single space, split splits on any whitespace. Which includes the newline. So, you actually have *3* fields, ("foo", "bar", "" -- the empty string following the newline), so it's the first case that's odd, not the second. It's the second magical feature that's to blame - in the absence of a limit, trailing empty fields are removed.$ perl -e 'warn 0+(@x = split " ", "foo bar\n");' 2 at -e line 1. $ perl -e 'warn 0+(($x, $y) = split " ", "foo bar\n");' 3 at -e line 1. $
You wouldn't have been surprised if you had chomped your line.
In reply to Re: Surprise: scalar(($x, $y) = split)
by JavaFan
in thread Surprise: scalar(($x, $y) = split)
by ambrus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |