On May 30, Ravi Channavajhala said:

>Does anyone have a nifty way to do a sort and comparison of two or more
>hash keys with multiple values per key?

>push (@{$a{$b}},$c);

>$b keeps changing, lets say in first instance it is "1" and
>"2" in second instance, and each instance has multiple values,
>e.g, instance "1" has "c1 c2 c3" and instance "2" has "c1 c2 c3
>c4 c5".  What's the easiest way to iterate through the hash and
>compare each instance values and print the differences?  Thanks
>for any answers.  In the above case, I like to see c4 and c5 as
>the values different from instance "1" to instance "2".

If you want to compute the difference between two lists, there are some
very nifty ways to do this in Perl.

  perldoc -q intersection

And here's a write-up I did for PerlMonks.org:

  http://www.perlmonks.org/index.pl?node_id=82149

You would use my difference() function like so:

  @diff = difference($a{$key1}, $a{$key2});

where $a{$key1} and $a{$key2} are hash values that hold array
references.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**        I no longer need a publisher for my Perl Regex book :)        **


Reply via email to