Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: when is destroy function called

by Anonymous Monk
on Mar 02, 2013 at 08:34 UTC ( #1021400=note: print w/replies, xml ) Need Help??

in reply to Re^2: when is destroy function called
in thread when is destroy function called

Secondly, I'm baffled ...

Nope, obey is printed before DESTROY. use the debugger, or just Devel::Trace, if you can't follow the text

$ perl -d:Trace dalek >> dalek:4: $| = 1; >> dalek:48: my $phaser = Phaser->new('Exterminator'); >> dalek:11: my ($class, $name) = @_; >> dalek:12: my $self = {}; >> dalek:13: $self->{name} = $name; >> dalek:14: return bless $self, $class; >> dalek:49: my $enemy = Dalek ->new($phaser); >> dalek:22: my ($class, $phaser_ref) = @_; >> dalek:23: my $self = {}; >> dalek:24: $self->{phaser} = $phaser_ref; >> dalek:25: return bless $self, $class; >> dalek:51: print 'My enemy is a ', ref $enemy, My enemy is a Dalek with a phaser named Exterminator >> dalek:53: print $enemy->exterminate(); >> dalek:30: return 'Firing phaser ' . $_[0]->{phaser}->{name} . " +\n"; Firing phaser Exterminator >> dalek:55: print 'My enemy must ', $enemy->obey(), >> dalek:35: return 'obey'; >> (eval 1)[dalek:55]:1: $enemy->exterminate() Use of uninitialized value in print at dalek line 55. My enemy must obey. His phaser is named Exterminator. Bye! >> dalek:40: my ($self) = @_; >> dalek:41: print 'DESTROYing a Dalek (phaser is ', $self->{phase +r}->{name}, ")\n"; DESTROYing a Dalek (phaser is Exterminator) >> dalek:42: $self->{phaser}->{name} = 'Obliterator'; >> dalek:60: print $@ if $@; Can't call method "exterminate" on an undefined value at (eval 1)[dale +k:55] line 1. >> dalek:62: print 'The phaser is named ', $phaser->{name}, "\n"; The phaser is named Obliterator

unintelligible (English?)

Its perfectly intelligible , its just a bit of fiction

Here is my example (which seems to prove your conclusion)

It doesn't really, the program dies before print prints anything -- it short circuits, failing to prove that order of cleanup/DESTROY isn't immediate

On a related note about global destruction order, see sub DESTROY: Strange ordering of object destruction (global destruction order not guaranteed

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2023-06-03 21:21 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (17 votes). Check out past polls.