Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: return a hash or undef

by hobbs (Monk)
on Aug 03, 2009 at 20:25 UTC ( [id://785547]=note: print w/replies, xml ) Need Help??


in reply to return a hash or undef

A) Don't return undef. Return () instead, and instead of checking for if (defined %resp), just check if (%resp). This works as long as you don't need to distinguish between a successful-but-empty return and a failure.

B) Return a hashref instead of a flattened hash, and assign the function's result to a scalar instead of a hash. Then undef, {}, and { foo => bar } are all distinguishable values (!defined $resp, !%$resp, and everything else, respectively.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found