Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: strange shift @_ problem

by ahunter (Monk)
on Jan 18, 2001 at 16:50 UTC ( [id://52758]=note: print w/replies, xml ) Need Help??


in reply to strange shift @_ problem

You are assuming that the expression is evaluated in a strict left-to-right order, which is not necessarily so, particularily when you use more than one type of operator. That is, in the second case,
[$_[1]..$_[2]]
is being evaluated before the shift is, so hence the @_ array is still as it was before the shift. Leftward list operators have a very high priority (see perlop), and this makes it look like perl evaluates the value of the index before the value of the list itself. To see this more clearly, try:
sub flob { print "Flob"; return 1; } sub adob { print "adob"; return ( 1,2,3 ); } $a = (adob())[flob()]; print "\n$a\n";
Which prints 'Flobadob', indicating that flob() is executed first. I can't find any docs that indicate that this is the expected behaviour, so it's probably not something you should rely upon working in future versions of perl.

Andrew.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://52758]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-20 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found