print 'My enemy must ', $enemy->obey(), undef($enemy), '. His phaser is named ', $phaser->{name}, eval('$enemy->exterminate()'), ". Bye!\n"; #### *** Before print statement *** $enemy------------------------->Dalek:{phaser=> + } (ref=1) | +---------------+ v $phaser------------------------>Phaser:{name=> + } (ref=2) | +--------------+ v 'Exterminator' (ref=1) argument stack: -empty- *** After print setup, before print executes *** $enemy------------------------->Dalek:{phaser=> + } (ref=2)<-+ | | +---------------+ | v | $phaser------------------------>Phaser:{name=> + (ref=2) | | | +--------------+ | v | 'Exterminator' (ref=2) | ^ | +--------------+ | argument stack: '. Bye!\n' | | eval('$enemy->exterminate()' | | ref---------------------------+ | '. His phaser is named ' | undef($enemy) | obey()<-ref---------------------------------+ 'My enemy must ' #### *** Executing through print, just after undef step *** $enemy--->undef Dalek:{phaser=> + } (ref=1)<-+ | | +---------------+ | v | $phaser------------------------>Phaser:{name=> + (ref=2) | | | +--------------+ | v | 'Exterminator' (ref=2) | ^ | +--------------+ | argument stack: '. Bye!\n' | | eval('$enemy->exterminate()' | | ref---------------------------+ | '. His phaser is named ' | undef($enemy) | obey()<-ref---------------------------------+ 'My enemy must ' #### *** Print just finished, now removing items from stack ... *** $enemy--->undef Dalek:{phaser=> + } (ref=1)<-+ | | +---------------+ | v | $phaser------------------------>Phaser:{name=> + (ref=2) | | | +--------------+ | v | 'Exterminator' (ref=1) | | argument stack: obey()<-ref---------------------------------+ 'My enemy must ' #### $enemy--->undef Dalek:{phaser=> + } (ref=0)<-+ | | +---------------+ | v | $phaser------------------------>Phaser:{name=> + (ref=2) | | | +--------------+ | v | 'Exterminator' (ref=1) | | argument stack: obey()<-ref---------------------------------+ 'My enemy must ' #### $enemy--->undef Dalek:{phaser=> } (ref=0)<-+ | $phaser------------------------>Phaser:{name=> + (ref=1) | | | +--------------+ | v | 'Exterminator' (ref=1) | | argument stack: obey()<-ref---------------------------------+ 'My enemy must ' #### $enemy--->undef {FREE MEMORY } $phaser------------------------>Phaser:{name=>'Exterminator'} (ref=1) argument stack: 'My enemy must ' #### #!/usr/bin/perl use Data::Dumper; use Devel::Peek; { package Foo; sub new { my $class = shift; my $val = shift; return bless { thing=>$val }; } sub val { my $self = shift; return "val: " . (++$self->{theVal}); } sub DESTROY { print "destroyed at ", ${shift}->{theVal}, "\n"; } } my $b = [ ]; my $t = Foo->new($b); print "--- before print ---\n"; Dump($b); Dump($t); print "--- Do the print ---\n"; print $t->val(), Dump($b), Dump($t), undef($t), Dump($b), Dump($t), ".\n"; print "--- after print ---\n"; Dump($b); Dump($t); #### $ perl ex_destructo.pl --- before print --- SV = RV(0x8c650b4) at 0x8c650a8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8c47818 SV = PVAV(0x8c4886c) at 0x8c47818 REFCNT = 2 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) SV = RV(0x8c650a4) at 0x8c65098 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8c476f8 SV = PVHV(0x8c4fa64) at 0x8c476f8 REFCNT = 1 FLAGS = (OBJECT,SHAREKEYS) STASH = 0x8c650c8 "Foo" ARRAY = 0x8c719d0 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "thing" HASH = 0x20b61f7d SV = RV(0x8c65054) at 0x8c65048 REFCNT = 1 FLAGS = (ROK) RV = 0x8c47818 SV = PVAV(0x8c4886c) at 0x8c47818 REFCNT = 2 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) --- Do the print --- SV = RV(0x8c650b4) at 0x8c650a8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8c47818 SV = PVAV(0x8c4886c) at 0x8c47818 REFCNT = 2 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) SV = RV(0x8c650a4) at 0x8c65098 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8c476f8 SV = PVHV(0x8c4fa64) at 0x8c476f8 REFCNT = 1 FLAGS = (OBJECT,OOK,SHAREKEYS) STASH = 0x8c650c8 "Foo" ARRAY = 0x8c6b8d0 (0:6, 1:2) hash quality = 125.0% KEYS = 2 FILL = 2 MAX = 7 RITER = -1 EITER = 0x0 Elt "theVal" HASH = 0x90484e39 SV = PVIV(0x8c5b04c) at 0x8cd6348 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 1 PV = 0x8cd17e0 "1"\0 CUR = 1 LEN = 4 Elt "thing" HASH = 0x20b61f7d SV = RV(0x8c65054) at 0x8c65048 REFCNT = 1 FLAGS = (ROK) RV = 0x8c47818 SV = PVAV(0x8c4886c) at 0x8c47818 REFCNT = 2 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) SV = RV(0x8c650b4) at 0x8c650a8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8c47818 SV = PVAV(0x8c4886c) at 0x8c47818 REFCNT = 2 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) SV = RV(0x8c650a4) at 0x8c65098 REFCNT = 1 FLAGS = (PADMY) val: 1. destroyed at --- after print --- SV = RV(0x8c650b4) at 0x8c650a8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8c47818 SV = PVAV(0x8c4886c) at 0x8c47818 REFCNT = 1 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) SV = RV(0x8c650a4) at 0x8c65098 REFCNT = 1 FLAGS = (PADMY)