Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Testing Hash with empty value in HoH

by salva (Canon)
on Jun 15, 2005 at 10:16 UTC ( #466854=note: print w/replies, xml ) Need Help??

in reply to Testing Hash with empty value in HoH

a reference to an empty hash is a true value.

Use values on scalar context to get the number of elements on the hash:

foreach my $k ( keys %{$hoh} ) { if( $hoh->{$k} and values %{$hoh->{$k}}) { print "$k\n"; }; }
updated following Limbic~Region advice.

Replies are listed 'Best First'.
Re^2: Testing Hash with empty value in HoH
by Limbic~Region (Chancellor) on Jun 15, 2005 at 12:40 UTC
    I agree with what you have said and how you have used your code, but for clarity believe you should add in scalar context. It may not be obvious to someone unfamiliar with Perl's DWYMery that in list context you get the list of values and in scalar context you only get the count.

    Cheers - L~R

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-01-18 08:36 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (52 votes). Check out past polls.