Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: Values passed into a sub routine

by Argel (Prior)
on Apr 20, 2011 at 22:05 UTC ( [id://900434]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Values passed into a sub routine
in thread Values passed into a sub routine

No, 0 and undef are not always the same. Take 'fork' as an example:
Does a fork(2) system call to create a new process running the same program at the same point. It returns the child pid to the parent process, 0 to the child process, or undef if the fork is unsuccessful.
So 0 indicates it is a child process while undef indicates failure. Not the same.

In general, you should be checking for definedness if your data is coming from outside of the script anyway. I usually do something like 'if( defined $foo && $foo ne ""){}' That way I avoid warnings about doing a string comparison with an undefined value (or whatever the warning message says). You are using 'strict' and 'warnings', right?

Anyway, your code above looks good.

Elda Taluta; Sarks Sark; Ark Arks

Replies are listed 'Best First'.
Re^5: Values passed into a sub routine
by wallisds (Beadle) on Apr 21, 2011 at 13:13 UTC

    I think I have a clearer understanding of 0 vs undef now, thanks!

    Q - You are using 'strict' and 'warnings', right?
    A - Yes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found