Michael Kraus wrote:
John W. Krahn wrote:
You should *always* verify that the files were opened correctly.
open INFILE, '<', $filename or die "Cannot open $filename: $!"; open OUTFILE, '>', "$filename.$$" or die "Cannot open $filename.$$: $!";
for my $line (<INFILE>) {
You imply above that you will read the file "a line at a time" however using a for loop will read the whole file into a list in memory. You need to use a while loop to read a line at a time.
while ( my $line = <INFILE> ) {
<snip>
You should verify that rename worked correctly
rename "$filename.$$", $filename or die "Cannot rename $filename.$$: $!";
The examples I've given are just that examples... Error checking functionality is up the end programmer... (And you are quite right, you should check the status of operations.) This is a beginers list, let's keep it friendly, eh?
Yes, this is a beginner level list, which makes it extra important to apply good programming practices in posted example code. Pointing out shortcomings in that respect is not unfriendly, it's useful advice.
... and FWIW ...
for my $line (<INFILE>) { # stuff }
is equivalent to:
while (my $line = <INFILE>) { # stuff }
No, it's not. John explained why.
Please read up on the topic, e.g. in "perldoc perlsyn", before objecting again.
If you are going to correct me, at least get it right and do it in a friendly manner! ;) :P :)
???
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
