Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to compare an empty key with another empty key in associative array

by bart (Canon)
on Oct 24, 2012 at 11:06 UTC ( #1000604=note: print w/ replies, xml ) Need Help??


in reply to How to compare an empty key with another empty key in associative array

That sounds like you're coming from PHP. Well, OK, I'll write a little utility function empty which should look a bit familiar. That way you can compare if 2 values are both empty.

sub empty { my $r = shift; if(!ref $r) { return !$r } if(ref $r eq 'HASH') { return !keys %$r } if(ref $r eq 'ARRAY') { return !@$r } if(ref $r eq 'SCALAR') { return !$$r } return !1; } $a = ''; $b = {}; $c = []; if(empty($a) && empty($b) && empty($c)) { print "PASS"; }


Comment on Re: How to compare an empty key with another empty key in associative array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-12-20 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls