Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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...


Comment on Re: Restoring the magic to the _ filehandle in Perl 5.8.9
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-07-23 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (141 votes), past polls