in reply to Examing local's stack

Don't know if this counts ;-)
$ perl -l use strict; use warnings; our $x = 3; foo(7); sub foo { my $oldx=$x; local $x = shift; print $x; print $oldx; }

Replies are listed 'Best First'.
Re^2: Examing local's stack
by polettix (Vicar) on Mar 22, 2006 at 10:36 UTC
    This won't work with recursive functions:
    #!/usr/bin/perl use strict; use warnings; our $x = 3; foo(7); sub foo { my $oldx=$x; local $x = shift; print "localised x = $x\n"; print " old x = $oldx\n"; foo(0) if $x; # recursive call, only 1 time } __END__ localised x = 7 old x = 3 localised x = 0 old x = 7

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.