Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: -pi -e argv repeater

by ikegami (Pope)
on Feb 02, 2007 at 15:45 UTC ( #597951=note: print w/replies, xml ) Need Help??

in reply to -pi -e argv repeater

Perhaps you'd like

use constant PIE_NO_BACKUP => ''; sub pie(&$@) { ( my $code, # Code ref local $^I, # PIE_NO_BACKUP, '~', '.bak', etc local @ARGV, ) = @_; local *_; # Protect caller's $_. while (<>) { chomp; $code->(); print($_, "\n"); } } # perl -i -pe 's///' file1 file2 pie { s/// } PIE_NO_BACKUP, 'file1', 'file2'; # perl -i.bak -pe 's///' file? data*.txt pie { s/// } '.bak', map { bsd_glob($_) } 'file?', 'data*.txt';


Update: Added missing "\n". Created constant for no backup. Added local *_;.

Replies are listed 'Best First'.
Re^2: -pi -e argv repeater
by jettero (Monsignor) on Feb 02, 2007 at 15:57 UTC

    $^I is apparently all I needed. I had no idea it would be so simple, thanks. I obviously should have just asked on the chatterbox... how embarassing.


Re^2: -pi -e argv repeater
by OfficeLinebacker (Chaplain) on Feb 03, 2007 at 19:08 UTC
    May I ask what the (&$@) in the sub declaration is for?

    I like computer programming because it's like Legos for the mind.

      It's a prototype.

      Without the prototype, you'd have to do
      pie sub { CODE }, SCALAR, LIST
      pie &func, SCALAR, LIST

      With the prototype, you can also do
      pie { CODE } SCALAR, LIST

        I see you disagree with Damian Conway (as expressed in Perl Best Practices--pp 194-196 for those of you following from home). I wish I understood better the exact thought processes behind each of your approaches.

        Either way, yes, $^I is the way to go (or, if you really want to be a Boy Scout about it, use English, only without the evil regexp vars, and use $INPLACE_EDIT in place of $^I).

        I like computer programming because it's like Legos for the mind.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://597951]
[marioroy]: I also have a Hobo driver for Forklift allowing folks to use in multiple classes, no conflicts with one another. That's not possible for P::FM.
[Discipulus]: congrats marioroy!
[marioroy]: CORE::wait works well eventhough multiple instances or classes using Hobo::Manager.
[Corion]: marioroy: I'm not sure what the normal use for the PID is in P:FM, but I guess that most programs just ignore or log it
[Corion]: Oh, yes, programs could call wait $pid, but if your $pid is an object, then you could add a ->wait method to it and wait $pid would call that automatically "thanks" to indirect object notation
[marioroy]: Just documentation edits is all that remains. Hobo::Simple provides foreach and forseq with identifier capability -- all transparently supporting array, hash, file handle, and seq 1 .. N.
[marioroy]: Corion Regarding PID, that's great. So will leave it so compatible with MCE::Hobo. e.g. ->create returns a Hobo object. Folks can get ->pid from it. So, that's not a problem.
[choroba]: ad readdir: 5.12 needed
[marioroy]: CORE::wait can block if another process reaps a worker from another class. MCE::Hobo takes care of that and transparently.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-05-26 08:46 GMT
Find Nodes?
    Voting Booth?