Rhandom has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -w package MyPack; use strict; sub new { return bless {},__PACKAGE__; } sub DESTROY { print "I'm destroyed\n"; } print "[$]]\n\n"; if( 1 ){ my $obj = MyPack->new(); print "Inside the IF (1)\n"; } print "Outside the IF (1)\n"; print "\n"; if( defined(my $obj = MyPack->new() ) ){ print "Inside the IF (2)\n"; undef $obj; } print "Outside the IF (2)\n"; print "\n"; if( defined(my $obj = MyPack->new() ) ){ print "Inside the IF (3)\n"; } print "Outside the IF (3)\n";
[5.006] Inside the IF (1) I'm destroyed Outside the IF (1) Inside the IF (2) I'm destroyed Outside the IF (2) Inside the IF (3) Outside the IF (3) I'm destroyed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object scope and DESTROY
by perrin (Chancellor) on Sep 24, 2001 at 21:05 UTC | |
by Rhandom (Curate) on Sep 24, 2001 at 21:08 UTC | |
by perrin (Chancellor) on Sep 24, 2001 at 22:07 UTC | |
|
Re: Object scope and DESTROY
by stefp (Vicar) on Sep 24, 2001 at 21:35 UTC | |
|
(tye)Re: Object scope and DESTROY
by tye (Sage) on Sep 24, 2001 at 22:21 UTC | |
|
Re: Object scope and DESTROY
by derby (Abbot) on Sep 24, 2001 at 21:50 UTC |