perlquestion
princepawn
In some code I have to now maintain, I first turned on use strict and use warnings. Then the following warning came up:
Scalar value @_[0] better written as $_[0]
<P>the error corresponds to this line:
<code>
( $paramName, $paramValue ) = split /=/, @_[0], 2;
</code>
<P>
My thinking on this code is that @_[0] creates an array slice consisting of the first element of @_. This array slice is a list, but is forced into scalar context because it is the second argument of split. Forcing a list into scalar context returns its last argument, which is the only argument in this case. Thus we would've been better off writing $_[0]
<P>
Sound good? I have to make this code change and justify it on this code which has had many years of comfortable use without use strict or use warnings. Any code change I make has to be rigorously justified, thus I want to 100% sure of what I am saying.