On Thu, 02 Jan 2014 11:56:26 -0500
Uri Guttman <u...@stemsystems.com> wrote:

> > Part of me wonders if File::Slurp should provide an in-place (not
> > slurping into RAM) editing feature which works like edit_file_lines
> > but line-by-line using a temp file, but that's probably feature
> > creep :)  
> 
> that IS tie::file which i didn't want for efficiency reasons. it has
> to read/write back and forth every time you modify an element.
> edit_file (and _lines) are meant to be fast and simple to use for
> common editing of files. as with slurping, i didn't expect them to be
> used on .5GB files! :)

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.)


-- 
David Precious ("bigpresh") <dav...@preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github



-- 
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