perlquestion
pboin
<p>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...
<p>Now, a FAQ is [id://173677]. 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.
<readmore>
<p>Here's a mini-case that I think should work (but doesn't):
<c>
#!/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
</c>
<p>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.
<readmore>
<p>Thank you Monasterians...