in reply to Surprise: scalar(($x, $y) = split)
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Surprise: scalar(($x, $y) = split)
by ambrus (Abbot) on Oct 28, 2011 at 15:24 UTC | |
|
Re^2: Surprise: scalar(($x, $y) = split)
by hbm (Hermit) on Oct 28, 2011 at 15:26 UTC |