On Fri, Apr 24, 2009 at 3:53 PM, Chas. Owens <chas.ow...@gmail.com> wrote:
> 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
>

Agreed, absolutely. My point was that just because something's wrapped
in in a BEGIN block doesn't mean one should assume it affects the
entire program, or be surprised when it doesn't

--j
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to