check out the following:

use strict; use Data::Dumper; my %hash=(); while(my $line=<DATA>){ chomp $line; my($key,$val)=split(/\s+=>\s+/,$line); my ($j,@k)=split(/[\|]/,$val); my $realkey=join('|',@k); if ( ! exists($hash{$realkey}) ){ $hash{$realkey}=[]; } push @{$hash{$realkey}},$key; } print Dumper(\%hash); __END__ 5030 => 5030|RED DOOR|10-14 1049 => 1049|RED DOOR|10-14 4990 => 4990|RED DOOR|10-14 959 => 959|RED DOOR|10-14 15047 => 15047|FLOWER|13+ 5565 => 5565|RED DOOR|10-14 4449 => 4449|RED DOOR|10-14 1065 => 1065|RED DOOR|10-14 2992 => 2992|RED DOOR|10-14 4956 => 4956|RED DOOR|10-14 17665 => 17665|FLOWER|13+ 6217 => 6217|RED DOOR|10-14 1224 => 1224|RED DOOR|10-14 424 => 424|RED DOOR|10-14 368 => 368|RED DOOR|10-14 451 => 451|RED DOOR|10-14 7752 => 7752|RED DOOR|10-14 4070 => 4070|RED DOOR|10-14 1312 => 1312|RED DOOR|10-14 17668 => 17668|FLOWER|13+ 4224 => 4224|RED DOOR|10-14 3588 => 3588|RED DOOR|10-14 11076 => 11076|RED DOOR|10-14 2986 => 2986|RED DOOR|10-14 2402 => 2402|RED DOOR|10-14 10834 => 10834|RED DOOR|10-14 849 => 849|RED DOOR|10-14 2954 => 2954|RED DOOR|10-14 11 => 11|RED DOOR|10-14 4093 => 4093|RED DOOR|10-14 492 => 492|RED DOOR|10-14 1861 => 1861|RED DOOR|10-14 4384 => 4384|RED DOOR|10-14 15037 => 15037|FLOWER|11+ 13044 => 13044|FLOWER|13+ 899 => 899|RED DOOR|10-14 292 => 292|RED DOOR|10-14 10421 => 10421|RED DOOR|10-14 4120 => 4120|RED DOOR|10-14 5557 => 5557|RED DOOR|10-14 3859 => 3859|RED DOOR|10-14 930 => 930|RED DOOR|10-14 649 => 649|RED DOOR|10-14 7511 => 7511|RED DOOR|10-14 648 => 648|RED DOOR|10-14 73 => 73|RED DOOR|10-14 12537 => 12537|RED DOOR|10-14 2485 => 2485|RED DOOR|10-14
which when run gives you:
$VAR1 = { 'FLOWER|11+' => [ '15037' ], 'RED DOOR|10-14' => [ '5030', '1049', '4990', '959', '5565', '4449', '1065', '2992', '4956', '6217', '1224', '424', '368', '451', '7752', '4070', '1312', '4224', '3588', '11076', '2986', '2402', '10834', '849', '2954', '11', '4093', '492', '1861', '4384', '899', '292', '10421', '4120', '5557', '3859', '930', '649', '7511', '648', '73', '12537', '2485' ], 'FLOWER|13+' => [ '15047', '17665', '17668', '13044' ] };

Now... your challenge is to understand what the code is doing. :-)


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: Counting Hash values? by blue_cowdawg
in thread Counting Hash values? by packetstormer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.