Am 02.01.2014 18:08, schrieb David Precious:

Oh, I was thinking of a wrapper that would:

(a) open a new temp file
(b) iterate over the source file, line-by-line, calling the provided
coderef for each line
(c) write $_ (potentially modified by the coderef) to the temp file
(d) finally, rename the temp file over the source file

Of course, it's pretty easy to write such code yourself, and as it
doesn't slurp the file in, it could be considered out of place in
File::Slurp.  I'd be fairly surprised if such a thing doesn't already
exist on CPAN, too.  (If it didn't, I might actually write such a
thing, as a beginner-friendly "here's how to easily modify a file, line
by line, with minimal effort" offering.)

A short look to CPAN brings out https://metacpan.org/pod/File::Inplace
what looks to do what OP wants.

Honestly I never used, and it can be that it has also a performance problem, but for at least I looked to it's source code and it implements it via a temporary file without saving the whole file.


Greetings,
Janek

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to