Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 ( [id://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"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found