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

Re: Declaring with my, assigning, and testing in same line (scope)

by tye (Sage)
on Dec 11, 2015 at 14:56 UTC ( [id://1150039]=note: print w/replies, xml ) Need Help??


in reply to Declaring with my, assigning, and testing in same line

It's the scoping of the parentheses around the my assignment that causes the problem.

The parens have nothing to do with it. A 'my' declaration has no effect until the statement after the 'my'. This is, at least in part, so you can do:

my $x = 2; { my $x = 3 * $x; # $x == 6 } # $x == 2

As to your question, you can get away with:

(@$_ = keys %foo) == 1 or die "Got more than one: @$_\n" for \my @v;

But I'm not sure it is worth it.

- tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found