in reply to list vs array context: odd error message...
First, it should be noted that there is no such thing as array context in Perl. The only contexts are scalar, list, and void (which is a special kind of scalar context). Scalar has several subcontexts, including string, numeric, and boolean. (It's generally accepted that wantarray was misnamed, and should have been wantlist instead.)
split is almost always used in a list context, where it returns a list of substrings split out from the target string. However, when split is used in a scalar context, as in $count = split ' ', $string split instead returns the size of the list of substrings. At the same time, the list of substrings is placed in the array @_. In other words, the behavior is effectively @_ = split ' ', $string; $count = @_;
This implicit assignment to @_ by split in scalar context is deprecated, which is why you receive a warning. You can avoid the warning by using a temporary array. $count = @tmp = split ' ', $string
However, you don't want the count of elements; you want a reference to an array, which you must ask for explicitly. $ref = [ split ' ', $string ] The anonymous array constructor puts split in list context (remember, there is no such thing as array context) and returns a reference to an array of substrings.
|
|---|