2009/4/24 Jay Savage <daggerqu...@gmail.com>: snip >> Hmm, I don't think it would reparse the whole file, but >> it does run in a BEGIN block...hmm, I must test it. >> > > It runs in a begin block, but it is still lexically scoped. Pragmata > are very special cases of modules that provide modifications of > compile-time behavior, and many of them perform sleight of hand behind > the scenes. Here, the sleight of hand is using utf8 to simply add a > bit mask to $^H and relying on the the behavior of the compiler hints. > > The important thing to remember about a BEGIN block that it is run as > soon as it is defined, where it is defined. Just because it is > executed early in the compile->optimize->run cycle does not mean that > it is magically transported to an earlier position in the file. > Generally, you want to apply the behavior introduced by a module to > have file scope, which is why use statements normally appear early in > the file. > > See perlpragma and the description of $^H in perlrun for details. snip
All of this is good information, but for one thing: not all pragmas are lexically scoped. Hence the need to test and/or read the docs. For instance, the re pragma[1] is only partially lexical: #!/usr/bin/perl use strict; use warnings; "foo" =~ /(o+)/; #re 'debug' still affects this line use re 'debug'; 1. http://perldoc.perl.org/re.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/