Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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]); }; }
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://820056]
[jdporter]: It doesn't have to be line by line. Just "my program" "writes" to the external prog and also/then "reads" from it.
LanX open (You are not allowed to open to a command that pipes both in and out, but see IPC::Open2, IPC::Open3, and Bidirectional Communication with Another Process in perlipc for alternatives.)
[jdporter]: IPC::Open2, I guess
[jdporter]: yes, that
[pryrt]: 1nickt: academically, perl -MDevel::Peek -lE 'Dump(42); Dump(42.0)'
[chacham]: have you ever wanted to vote -- on a post because of the signature?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2017-05-24 20:33 GMT
Find Nodes?
    Voting Booth?