On 01/02/2014 12:08 PM, David Precious wrote:
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.)



it wouldn't be a bad addition to file::slurp. call it something like edit_file_loop. if you write it, i will add it to the module. you can likely steal the code from edit_file_lines and modify that. i would document it as an alternative to edit_file_lines for very large files.

it will need pod, test files and good comments for me to add it. credit will be given :)

thanx,

uri

--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com

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