http://qs1969.pair.com?node_id=785547


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.)