in reply to Lexicals in if() scope gotcha!
#!/usr/bin/perl print "foreach...\n"; foreach (Foo->new) {} print "after foreach\n"; print "while...\n"; while (my $object = Foo->new && 0) {} print "after while\n"; print "for...\n"; for (my $object = Foo->new; 1 < 0; ) {} print "after for\n"; package Foo; sub new { my $self = bless {},shift; print "CREATED $self\n"; $self } sub DESTROY { print "DESTROYED $_[0]\n" } __END__ bester:~/tmp> monk.pl foreach... CREATED Foo=HASH(0x22494) DESTROYED Foo=HASH(0x22494) after foreach while... CREATED Foo=HASH(0x305f0) DESTROYED Foo=HASH(0x305f0) after while for... CREATED Foo=HASH(0x22494) after for DESTROYED Foo=HASH(0x22494)
Perl's notion of the right time to call a destructor is not well-defined currently, which is why your destructors should not rely on when they are called.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Lexicals in if() scope gotcha!
by Mr. Muskrat (Canon) on Mar 31, 2004 at 02:51 UTC | |
|
Re: Re: Lexicals in if() scope gotcha!
by QM (Parson) on Mar 31, 2004 at 02:31 UTC | |
by merlyn (Sage) on Mar 31, 2004 at 12:27 UTC | |
by Ovid (Cardinal) on Mar 31, 2004 at 06:48 UTC |