in reply to Editing a text file without reading it into an array

You could (but of course, TMTOWTDI):

open ($in, $infile) or die("Cannot open $infile"); open ($out, '>', $outfile) or die("Cannot open $outfile"); flock($out, 2); #lock output file while(<$in>){ ### edit each line here using $_ print $out $_; ## print each line to output } close($out); close($in);

As for monks to study, I suggest for starters looking at the posts of merlyn, tilly, jcwren, erudil, and crazyinsomniac (in no particular order).

Every monk here has something from which you can learn, and I'm sure you will have many ideas to contribute.

Update: followed Aristotle's suggestion and replaced foreach with while.
I should have known this, because "while(<$fh>)" was an answer to a question I previously asked. Sorry for the confusion, I'm just foreach happy. :)

John J Reiser
newrisedesigns.com

Replies are listed 'Best First'.
Re: Re: Editing a text file without reading it into an array
by cjf (Parson) on Jun 30, 2002 at 05:59 UTC
    As for monks to study...

    I recommend taking a stroll over to the Tutorials section. Most would probably find it serves as better introductory material than camel code ;-). Also, if you're looking for a good Perl book Learning Perl is an excellent choice.

      thanks :)
Re^2: Far across cyberspace
by Aristotle (Chancellor) on Jun 30, 2002 at 10:59 UTC
    Careful. foreach expands the bracketed list first so you still slurp the file. You only sidestep the declaration of a temporary array variable. Your code will however work exactly as intended - without the need for any other modifications - if you simply substitute foreach for while.

    Makeshifts last the longest.