Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Restoring the magic to the _ filehandle in Perl 5.8.9

by ikegami (Pope)
on Jan 27, 2010 at 23:29 UTC ( #820056=note: print w/replies, xml ) Need Help??


in reply to Restoring the magic to the _ filehandle in Perl 5.8.9

As you've stated, if you delay the execution of the code, there's no problem. I presume the reason you're using BEGIN is that the code inside will end up in a module. But you're not out of luck. Execution of INIT blocks are delayed until the main script has finished compiling.

If you change

BEGIN { *::_ = sub { # Shout to be understood return uc($_[0]); }; }
to
BEGIN { INIT { *::_ = sub { # Shout to be understood return uc($_[0]); }; } }

then the parser won't think the "_" in "-l _" is a function call since there's no function called "_" yet.

Caveat: Modules loaded after the script has been compiled...

Replies are listed 'Best First'.
Re^2: Restoring the magic to the _ filehandle in Perl 5.8.9
by clinton (Priest) on Jan 28, 2010 at 13:27 UTC

    Good thinking. Unfortunately, other code of mine relies on sub _ being present at compile time: it doesn't immediately localise those phrases, but wraps each phrase in an object which i18n's the phrase on stringification.

    It turns out that, of all the modules I'm using in my app, only File::Find and File::MMagic use -l _, so I may just preload those.

    thanks for the tip, Ikegami

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://820056]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2016-12-04 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (69 votes). Check out past polls.