>>>>> "PL" == Paul Lalli <> writes:
>> perldoc -f push ( to add a last line to your existing file)..
PL> Gah. You are suggesting the OP read the entire file into memory,
PL> modify the array, and then print the entire array back to the file?
PL> Please don't do this. Ever.
why not? if the file is small enough (and small is pretty big by today's
ram standards) it is simpler and faster to slurp in many cases. this
could be done with:
use File::Slurp ;
my $text = read_file( 'file' ) ;
$text =~ s/Nevada/California/g ;
write_file( 'file', "FirstLine\n", $text, "LastLine\n" ) ;
and when the edit_file feature is added it would be something like:
edit_file( 'file', sub{ s/Nevada/California/g ;
$_ = "FirstLine\n${_}LastLine\n" } ) ;
i totally get line by line processing but the bias against slurping
small files is silly IMO. with stdio or filesystem buffer sizes like 64k
now, you don't save any real ram with line by line and slurping usually
will be faster.
uri
--
Uri Guttman ------
--------
http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org