This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlfunc: Correct note about eval in DB package
authorFather Chrysostomos <sprout@cpan.org>
Thu, 15 Nov 2012 20:38:27 +0000 (12:38 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 15 Nov 2012 23:57:13 +0000 (15:57 -0800)
It’s where the subroutine is defined, not the current package,
that matters.

#!perl -l
sub { my $x = 3; foo(); print $x }->();
sub foo { package DB; eval q"$x = 42" }
__END__
3

#!perl -l
sub { my $x = 3; DB::foo(); print $x }->();
package DB;
sub foo { package main; eval q"$x = 42"; }
__END__
42

pod/perlfunc.pod

index 98d7673..6a7dcdb 100644 (file)
@@ -1915,7 +1915,8 @@ errors:
 C<eval BLOCK> does I<not> count as a loop, so the loop control statements
 C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
 
-An C<eval ''> executed within the C<DB> package doesn't see the usual
+An C<eval ''> executed within a subroutine defined
+in the C<DB> package doesn't see the usual
 surrounding lexical scope, but rather the scope of the first non-DB piece
 of code that called it.  You don't normally need to worry about this unless
 you are writing a Perl debugger.