Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Corrector

by quinkan (Monk)
on Dec 13, 2008 at 06:02 UTC ( #730109=note: print w/ replies, xml ) Need Help??


in reply to Corrector

Save yourself effort and use one of the "Slurp" modules, given that Perl 6 is to support even smarter things. These let you read all file content into a single variable. Less code to go wrong. Thus, one fragment might read:

use File::Slurp: # get one file here, as $file my($bakfile, $file, $text); # maybe set up file renaming with something like this... ($bakfile = $file ) =~ s/\.([^.]+)$/\.bak/; # then, the main bit $text = read_file($file); $text =~ s/this/that/smg; rename($file, $bakfile); write_file($file, $text);
Another possible version something like:
use Perl6::Slurp; #<= only handles input at present use File::Slurp; # permits writing. # and then.... .... $text = slurp($file); $text =~ s/$this/$that/smg; ... with renaming here ? (see above). write_file($file, $text);
And BTW do you really need that chomp and/or intend to remove newlines?


Comment on Re: Corrector
Select or Download Code
Re^2: Corrector
by gok8000 (Scribe) on Dec 28, 2008 at 15:49 UTC

    Thank you for the suggestion.

    The commented chomp was left in the source for a possible future use, but at present newlines are not removed.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-31 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls