Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Lexicals in if() scope gotcha!

by liz (Monsignor)
on Mar 30, 2004 at 23:32 UTC ( #341138=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    if (my $object = Foo->new) {}
    print "after if\n";
    ...
    package Foo;
    sub new { my $self = bless {},shift; print "CREATED $self\n"; $self }
    sub DESTROY { print "DESTROYED $_[0]\n" }
    
  2. or download this
    CREATED Foo=HASH(0xfc65c)
    after if
    DESTROYED Foo=HASH(0xfc65c)
    
  3. or download this
    CREATED Foo=HASH(0xfc65c)
    DESTROYED Foo=HASH(0xfc65c)
    after if
    
  4. or download this
    use Internals qw(SetRefCount);
    if (my $object = Foo->new) { SetRefCount( $object,1 ) }
    ...
    DESTROYED Foo=HASH(0xfc65c)
    after if
    Attempt to free unreferenced scalar: SV 0xfc65c.
    
  5. or download this
    {
    if (my $object = Foo->new) { }
    ...
    CREATED Foo=HASH(0xfc65c)
    DESTROYED Foo=HASH(0xfc65c)
    after if
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2016-02-10 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





    Results (354 votes), past polls