Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Comparing 2 hash tables where values are stored in arrays

by Athanasius (Archbishop)
on Sep 06, 2014 at 03:27 UTC ( #1099736=note: print w/replies, xml ) Need Help??


in reply to Re: Comparing 2 hash tables where values are stored in arrays
in thread Comparing 2 hash tables where values are stored in arrays

I'd use List::Compare (though I'm not sure I like its object-oriented interface)

Then use the same author’s List::Compare::Functional instead  :-)

#! perl use strict; use warnings; use feature qw/ say /; use List::Compare::Functional qw/ get_unique get_complement /; use List::MoreUtils qw/ uniq /; my %hash1 = (abc => [1, 2, 3, 4]); my %hash2 = (abc => [1, 3, 5, 7]); $, = ','; foreach my $key (uniq(keys %hash1, keys %hash2)) { say get_unique ( [ $hash1{$key} // [], $hash2{$key} // [] ] ); say get_complement( [ $hash1{$key} // [], $hash2{$key} // [] ] ); }

Output:

13:23 >perl 1000_SoPW.pl 2,4 5,7 13:23 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^3: Comparing 2 hash tables where values are stored in arrays
by AppleFritter (Vicar) on Sep 06, 2014 at 09:27 UTC
    Oh, now that's useful! Thanks for the pointer, brother!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1099736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-08-18 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?