[Kc] should i submit this (or at least the lack of a warning) as a bug?
David Nicol
davidnicol at gmail.com
Wed Feb 28 21:49:15 PST 2007
The situation is, that the C<use> construct does its thing inside a BEGIN
block. There is an implied scope around a perl expression that starts "use ..."
and that can confuse things when you try to declare a lexical in the
arguments to C<use>.
This has bitten me more than once, and thre is no "lexical within implied
scope may disappear" warning when it happens, at least in 5.8.6.
David at PAPERCLIP ~/perlhacking/scopebug
$ perl -wle 'use lib "."; use SetToFour my $x; print $x'
Name "main::x" used only once: possible typo at -e line 1.
Use of uninitialized value in print at -e line 1.
David at PAPERCLIP ~/perlhacking/scopebug
$ perl -wle 'use lib ".";my $x; use SetToFour $x; print $x'
4
David at PAPERCLIP ~/perlhacking/scopebug
$ cat SetToFour.pm
package SetToFour;
sub import { $_[1] = 4 }
1;
--
"I've never been elected dog-catcher and I've never had an employee."
-- Bruce Sterling
More information about the kc
mailing list