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

Re^2: problem with do and file existence.

by emilford (Friar)
on Oct 04, 2005 at 15:43 UTC ( [id://497293]=note: print w/replies, xml ) Need Help??


in reply to Re: problem with do and file existence.
in thread problem with do and file existence.

Sorry for the lack of clarity. We have our main file, say homepage.cgi, that will execute 1 of 2 Perl files: x.cgi and y.cgi. Both x.cgi and y.cgi worked correctly, being called by homepage.cgi's do. Someone else went in and modified x.cgi to include the if (-e "/some/file") code that I mentioned above. Executing x.cgi loads, but I know get an error message with the do in homepage.cgi, complaing that the file in x.cgi does not exist. So the issue is that something with the file check in x.cgi causes the do to dork up in homepage.cgi. Hope that makes better sense.

Replies are listed 'Best First'.
Re^3: problem with do and file existence.
by sauoq (Abbot) on Oct 04, 2005 at 15:50 UTC

    Yes, that makes much more sense. Your problem is that the -e is setting $! when the file doesn't exist. It's staying set when you get back to your homepage.cgi. And apparently your x.pl script is returning undef. I'd check the logic in x.pl to see if that new if statement causes a return.

    Update: To elaborate, if you want to do manual error checking like that, it's necessary for you to return something useful from the file you do. Otherwise, the last expression evaluated in the file will be your return value. If that value is undef, you can't tell it apart from those times when do returns undef because of an error or a non-existent file.

    -sauoq
    "My two cents aren't worth a dime.";
    
      It doesn't cause a return, but it is the last bit of code executed in x.cgi. By why would the file not existing cause x.cgi to return undef? How can this be resolved?

        I was updating as you replied. The last expression evaluated is the value returned by do. If it is undef, then you can't tell it apart from the times when do returns an undef because the file doesn't compile or doesn't exist.

        If that if clause is the last thing being evaluated, and the file doesn't exist, it is evaluating to undef and being returned. (And setting $! to boot.) You can probably take care of it with else { return 0 } or similar.

        -sauoq
        "My two cents aren't worth a dime.";
        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found