Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: return a hash or undef

by hobbs (Monk)
on Aug 03, 2009 at 20:25 UTC ( #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? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-08-10 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?