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

pboin has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to improve my perl-fu a bit, and I think this is a case where I could map or grep. However, it's not working the way I think it should, and I could use a nudge...

Now, a FAQ is How do I find out if a hash is empty?. That's not exactly what I want to do. I have a hash, I know there are keys out there, but I want to get a quick count of how many of those keys have non-empty values.

Here's a mini-case that I think should work (but doesn't):

#!/usr/bin/perl use strict; use Data::Dumper::Simple; my %a = ( one => 'red', two => '', three => 'blue' ); my @rtn = map {$a{$_} !~ /^$/;} keys(%a); print Dumper(@rtn); print "Keys w/ non-empty values: " . scalar(@rtn) . "\n"; __RESULTS__ @rtn = ( 1, 1, '' ); Keys w/ non-empty values: 3

I think that the matching operator is having its results stored in @rtn. Then, when I get use that return in scalar context, the result isn't quite what I was looking for. Now I have to figure out how many non-empties are in my array instead of my hash, which is pretty much where I started.

Thank you Monasterians...