Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Handling weird return values with or die

by Abigail (Deacon)
on Jul 05, 2001 at 19:57 UTC ( [id://94140]=note: print w/replies, xml ) Need Help??


in reply to Re: Handling weird return values with or die
in thread Handling weird return values with or die

It is not a matter of opposing standards. There are two different things. First, there are the function calls, whose behaviour is strictly defined (or else they would be unusuable). At the C level, failure is often indicated by a return value of -1, or NULL, and the reason of failure is passed in a global variable, errno. Not very intuitive (IMO), and Perl, being the thin layer it is above Unix/C, only makes it slightly more convenient. It returns 0 on failure. The reason of failure is still passed in a global variable, $! (which explains that variable).

The return values of spawned process have nothing to do with the shell. It's the other way around. Processes typically return 0 indicating success, and anything else for failure. There's no global variable to set, all they can do is return a single integer. "0 on success" is a mere convention. It's just because this convention is followed so often, typical shell Boolean logic is "reversed"; 0 is true, other integers are false.

-- Abigail

Replies are listed 'Best First'.
Re: Re: Handling weird return values with or die
by mvaline (Friar) on Jul 05, 2001 at 20:37 UTC
    Thank you; that was quite a good explanation. I had never considered the semantic relationship between errno and $!.

    I always find it helpful to learn context around the tools I use. I believe that if I can think a little more like the designer of the tool when I'm using it, I will be that much more effective.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://94140]
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: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found