Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: File Open Error

by aaron_baugher (Curate)
on May 09, 2012 at 13:41 UTC ( #969626=note: print w/replies, xml ) Need Help??


in reply to File Open Error

Your open command says to open the file named "data.txt," and put a file descriptor attached to it in the scalar variable $file. Probably not what you intended.

By the way, while there are times that it makes sense to slurp an entire file into an array and then step through the array, it's not a good habit to get into when you don't need to.

# Instead of: open $file, .... my @data = <$file>; close $file; foreach my $line (@data){ # do stuff with $line } # get in the habit of doing this: open $file, .... while( my $line = <$file> ){ # do stuff with $line } close $file;

Aaron B.
Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969626]
help
Chatterbox?
LanX "If Croesus goes to war he will destroy a great empire."
[LanX]: s/Croesus/May/

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-03-29 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (344 votes). Check out past polls.