|Welcome to the Monastery|
Re^3: Wrong content of variable passed to subby afoken (Parson)
|on Aug 24, 2013 at 07:53 UTC||Need Help??|
I thought that @_ meant the list passed to the sub, so I used $_ when I passed a single element.
@_ contains the list of arguments for a sub, but you want the first argument of that array, which is $_. $_ is something completely different, as you already know.
There are two common idioms for accessing arguments:
Of course, you can also write
But that is uncommon and has some strange accent. Stick with the first two variants. Having only one argument needs no exception, you can use the list assignment even for a single argument, no need for shift:
Just remember the parentheses, or else $onlyarg will contain the number of arguments, in this case 1. Not what you want.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)