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

Re^2: if(my) scope

by cdarke (Prior)
on Apr 16, 2009 at 15:44 UTC ( #758016=note: print w/ replies, xml ) Need Help??


in reply to Re: if(my) scope
in thread if(my) scope

Although I am sure you are right, how come:

use strict; use warnings; use Devel::Peek; my $true = 1; my $ref; if ($true) { my $fred = 42; $ref = \$fred; } print Dump($$ref);
Gives:
SV = IV(0x3b2e0) at 0x3b2e4 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 42
A reference count of 1, not 2?


Comment on Re^2: if(my) scope
Select or Download Code
Re^3: if(my) scope
by ikegami (Pope) on Apr 16, 2009 at 15:53 UTC
    You changed
    if (my $var) { ... }
    to
    if (...) { my $var; ... }
    use strict; use warnings; use Devel::Peek; my $ref; if ((my $fred = 42), 1) { $ref = \$fred; Dump($$ref); } Dump($$ref);
    SV = IV(0x816a5cc) at 0x814f684 REFCNT = 2 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 42 SV = IV(0x816a5cc) at 0x814f684 REFCNT = 2 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 42

    A scope is created for if's curlies, but only a compile-time scope is created for the condition expression.

    Btw, note the proper usage of Dump.

      Doh!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-10-25 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls