|Keep It Simple, Stupid|
Re^4: RFC: beginner level script improvement (various comments)by smls (Friar)
|on Oct 31, 2013 at 03:20 UTC||Need Help??|
"I read the unshift and sub documentation again and I still don't understand your hint."
Ah I meant shift of course, apologies for the confusion.
As far as I understand the @_ is a list that contains all arguments the sub was called with and consequently $_[x] would contain the element of that array with index x.
while I think shift only makes sense if something might or might not be present at a specific index after 0
Not sure what you mean by that. shift removes the first value off the list, so all remaining elements of the list move one index to the left (that's why it's called "shift"):
It works exactly the same when used on @_ (which is the default when shift is called without argument).
my ($bar_ref) = @_; #same as above but I can not process anything else from the list
Not sure what you mean by that, either. Unlike shift, the assignment does not modify @_. Its effect is identical to that of:
When both sides of an assignment are lists, Perl goes from left to right, assigning the first element of the RHS ("right-hand-side") to the first element of the LHS, then the second RHS element to the second LHS element, and so on, for as many elements as there are on the LHS: