Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: perl can find the file but can not open the file

by graff (Chancellor)
on Mar 09, 2013 at 19:42 UTC ( #1022618=note: print w/ replies, xml ) Need Help??


in reply to perl can find the file but can not open the file

You're using quotes where you don't need to, and as indicated above, the single-quotes in the open statement are not only unnecessary, but cause the "file not found" error. Try it like this:

die "$file not found\n" unless ( -e $file ); open( FH0, $file ) or die "Unable to open $file: $!\n"; ...
In that version, I took advantage of the fact that "open" assumes "for reading" as a default; if the file name returns "true" with '-e', then it exists. But there might still be issues with being able to read it. If '-r' returns true for the file, then it's virtually certain that "open" for reading will succeed.


Comment on Re: perl can find the file but can not open the file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-07-05 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls