Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Replace strings in text file

by haukex (Bishop)
on Sep 23, 2018 at 08:03 UTC ( #1222881=note: print w/replies, xml ) Need Help??


in reply to Replace strings in text file

TIMTOWTDI, if you don't mind me plugging one of my own modules, File::Replace:

use warnings; use strict; use File::Replace 'replace'; my $lookuptxtfile = "lookup.txt"; my $fh = replace($lookuptxtfile); while (<$fh>) { s/The action failed./failed_build/g; print $fh $_; } close $fh;

Or, if a single filehandle is too much magic for your taste:

use warnings; use strict; use File::Replace 'replace3'; my $lookuptxtfile = "lookup.txt"; my ($infh,$outfh,$repl) = replace3($lookuptxtfile); while (<$infh>) { s/The action failed./failed_build/g; print $outfh $_; } $repl->finish;

Note: This is a re-post of a node that was lost.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1222881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-05-26 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?