Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Replace strings in text file

by haukex (Archbishop)
on Sep 23, 2018 at 08:03 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found