Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
---------------------- output:#!/local/bin/perl -w use warnings; use strict; # Runs the sub reference in arg #1 sub Doit { &{$_[0]}; } # Start of a big block - don't want to pollute { my $x = 777; my $y = 222; print "Initialized, what's the values?"; print " x = $x\n"; print " y = $y\n\n"; sub mysub { print " Start of subroutine\n"; print " what's x? (forget y for now)\n"; print " x = $x\n\n"; print " Going to child block\n"; print " let's inspect the variables again:\n"; { Doit( sub { print "x = $x\n\n"; print " y = $y\n\n"; } ); } } } # Big Block mysub();
>perl perlbug.pl
Initialized, what's the values? x = 777
y = 222
Start of subroutine
what's x? (forget y for now)
x = 777
Going to child block
let's inspect the variables again:
x = 777
Use of uninitialized value in concatenation (.) or string at perlbug.pl line 31
y =
(This behavior has been checked on Perl 5.6.1 and 5.8.8)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lexical Scoping and Anonymous Subroutines Passed To Functions
by jdporter (Paladin) on Jun 15, 2007 at 21:30 UTC | |
|
Re: Lexical Scoping and Anonymous Subroutines Passed To Functions
by Anonymous Monk on Jun 15, 2007 at 21:49 UTC | |
by dave_the_m (Monsignor) on Jun 15, 2007 at 22:07 UTC | |
|
Re: Lexical Scoping and Anonymous Subroutines Passed To Functions
by ambrus (Abbot) on Jun 16, 2007 at 15:30 UTC |