P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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]
the error corresponds to this line:
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] 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. In reply to @_0 vs. $_0 by princepawn
|
|