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

Re: two statements in or

by Marshall (Canon)
on Jun 27, 2009 at 10:35 UTC ( [id://775284]=note: print w/replies, xml ) Need Help??


in reply to two statements in or

I would do this:
#!/usr/bin/perl -w use strict; open (IN, "somefile") || warn "unable to open somefile"; open (IN, "somefile") || hey_do_something(); sub hey_do_something { print "some stuff in a sub\n"; print "more stuff in a sub\n"; }
In the above normally "warn" would be "die". In almost all cases an OPEN should succeed on a file_path (usual case is that you know a valid file_path). There are exceptions of course, but they are aren't "normal".

Anyway above "warn", "die", "hey_do_something" are just subroutines to execute if the OPEN fails.

Update: If you are working with some user input, I would check that the file exists before even getting to the "open" statement unless the error message from the open() is very clear: open() or die "can't open $file $!";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2026-02-18 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.