Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: write exact lines of file

by helgi (Hermit)
on Oct 09, 2003 at 09:52 UTC ( #297859=note: print w/ replies, xml ) Need Help??


in reply to Re: write exact lines of file
in thread write exact lines of file

No warnings, no strictures. Bad.

use warnings; use strict;
You should always, yes, always, check the results of system calls for errors.

open(FILE, filename) or die "Cannot open filename:$!\n";

There is absolutely no need in any of the examples to read the file into an array. It is faster and far less memory wasteful to loop through the file with while:

while (<FILE>) { # do stuff }

In your 3rd example, you are not opening the file for writing, so writing will fail. This would have been caught if you had allowed warnings.

There are more problems, but since many posts above have dealt with this problem much better, I will cease now.


--
Regards,
Helgi Briem
hbriem AT simnet DOT is


Comment on Re: Re: write exact lines of file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://297859]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2014-08-29 16:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (281 votes), past polls