in reply to "use strict" not too strict
On top of the other points made here I thinks its worth pointing out that subs are essentially package variables that our() doesnt care about (it turns out there are quite a few of them *Globs are exempt from strict as are Fully::Qualified::Items and the punctuation and magic vars). And in fact the magic involved in your example (that of exporting subs) exploits this fact. Consider this
use strict; *foo=sub{print "foo"}; foo();
Which is in fact very close to what that use Module qw(fubar); actually does behind the scenes. When perl sees use Module qw(fubar); it doesnt think to itself "they want to alias Module::fubar() to main::fubar()" or any such declaration. Instead perl just thinks "oh, they want to pass an argument to that funny looking subroutine that happens to be a file full of subroutines, including one called import() which is in fact where I shall pass those arguments" and once the arguments are passed to import(), what import() does with them is entirely up to it. As it happens normally the result is that a line like
*"${pack}::${name}"=\&fubar;
Which is just an assignment that happens to set up the symbol table in such a way that it results in the appearance of the subroutine being "exported", which of course it isnt, it stays right where it is, and just pretends to be in both packages (if it was in fact a closure it would still be bound to the context inside the other module.)
Youll find that a lot of stuff in perl that has to do with package variables doesnt play quite as you might expect with strict, filehandles, formats etc.
|
|---|