Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Duh. 'my' scope in if else blocks.

by ikegami (Patriarch)
on Dec 11, 2007 at 19:57 UTC ( [id://656468]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Duh. 'my' scope in if else blocks.
in thread Duh. 'my' scope in if else blocks.

doom's explanation is wrong. It has nothing to do with order. Even if you fixed the order, it still wouldn't work.

(my $t = shift) and print $t; # Fails.

Variables cannot be used (by name) in the statement in which they are declared. This allows statements such as my $t = $t; to work.

print $t if (my $t = shift); # Fails. my $t = shift; print $t if $t; # Ok. if (my $t = shift) { print $t; } # Ok.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found