Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 meditating upon the Monastery: (5)
As of 2015-07-28 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls