in reply to Avoid re-invocation for -pie processing

Assuming the Example is Just an Example

Maybe I read between the lines a little too much but my guess is that your example is just that, an example, and you really are asking how to avoid recompiling code and repeatedly invoking Perl. The answer to that is likely a process (crude but effective):

use strict; use Daemon::Easy sleep=>5, stopfile=>'stop', pidfile=>'pid', callback= +>'worker'; use File::Find qw~find~; run(); sub worker { die 'Improper setup -- must have an ./old folder!' unless (-d './old +'); die 'Improper setup -- must have a ./pass folder!' unless (-d './pas +s'); find(\&wanted, qw~/tmp/working/perlmonks/lib/11156715~); } sub wanted { if ( (-f $File::Find::name) && ($File::Find::name=~m/\.pl$/ ) && ($File::Find::name !~m/code\.pl$/) ) { print "open the file, replace comments, resave orig. to ol +d folder and updated one to pass folder --- $File::Find::name\n"; } }

Errr....you can do this in like a bazillion other ways in Perl. Off the top of my head you could use Dancer or Mojolicious or just hack up an HTTP server, etc.

Otherwise...

Here is where I struggled with your question -- why, oh why, are you trying to optimize something as trivial as this? I mean, it should be a one liner. I normally wrap stuff like this in a bash script and leave it alone:

#!/bin/bash perl -pi.bak -e 's{a}{b}g' $1

Epilogue

I have been messing around with Javascript so much that I started thinking about ways to make asynchronous calls after copying a file to my folder. Perhaps I would use this Future module...

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re^2: Avoid re-invocation for -pie processing
by seismofish (Novice) on Jan 10, 2024 at 16:53 UTC

    Hi,

    My example absolutely should be a one-liner - if invoked from the shell. What I wanted to do, however, was achieve the same thing from inside a lengthy perl script (that does lots of other things) without (a) having to code the whole thing with proper error-checking etc and without (b) forking another perl just to save typing.

    Ikegami's answer is closest to the spirit of my request but the answers that suggest using Path::Tiny are probably easier to read, which is a "good thing"™.

    Thanks for your interest.

    <°}}}>«<