Syntactic Confectionery Delight | |
PerlMonks |
Re: Count values in a hashby ack (Deacon) |
on Jan 11, 2011 at 21:53 UTC ( [id://881776]=note: print w/replies, xml ) | Need Help?? |
Head the other responders' replies. Failure to de-reference your hash and array are the source of the difficulty as the other responders noted. Here is a quick, short set of code that does what I believe your looking to do. I include it just so that you can see one way to do it. Of course, as in all of Perl, TMTODI. Cheers.
The resulting output is:
Which is what I believe you are after. The only difficulty is that the pattern match, $_ =~ /X/g is not very general...it wouldn't, for instance, see multiple occurances of 'X' in a value (you, the OP, didn't specify what to do if such an occurance presented itself) nor would it distinguish upper case 'X' from a lower case 'x' (you didn't specify if that mattered). But I figured either you'd already know how to handle those situations or they would be good explorations of Perl for you. Also note that I just initialize the hash with the example that you gave rather than reading it in from a file because I felt that it would just obscure the main body.
ack
Albuquerque, NM
In Section
Seekers of Perl Wisdom
|
|