use strict; use warnings; use Devel::Peek; $\=$/; sub foo { my $bar = @_ ? shift : 1; print "in foo(): "; Dump($bar); sub bar { my $foo = shift; print "in bar(): "; Dump($bar); return $foo * (++$bar); }; my $result = bar($bar); $result; } print "calling foo(1): 1 * 2 = " . foo(1); print "calling foo(): 1 * 2 = " . foo(); print "calling foo(): 1 * 2 = " . foo(); print "calling bar(5): 3 * 5 = " . bar(5); print "calling foo(3): 3 * 4 = " . foo(3); __END__ Variable "$bar" will not stay shared at bar.pl line 17. in foo(): SV = IV(0x88d0b1c) at 0x88b57a4 REFCNT = 2 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 1 in bar(): SV = IV(0x88d0b1c) at 0x88b57a4 REFCNT = 2 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 1 calling foo(1): 1 * 2 = 2 in foo(): SV = IV(0x88d0e0c) at 0x88b5720 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 1 in bar(): SV = IV(0x88d0b1c) at 0x88b57a4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 2 calling foo(): 1 * 2 = 3 in foo(): SV = IV(0x88d0e0c) at 0x88b5720 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 1 in bar(): SV = IV(0x88d0b1c) at 0x88b57a4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 3 calling foo(): 1 * 2 = 4 in bar(): SV = IV(0x88d0b1c) at 0x88b57a4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 4 calling bar(5): 3 * 5 = 25 in foo(): SV = IV(0x88d0e0c) at 0x88b5720 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 3 in bar(): SV = IV(0x88d0b1c) at 0x88b57a4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 5 calling foo(3): 3 * 4 = 18