Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Reconcile one list against another

by samwyse (Scribe)
on May 04, 2011 at 21:03 UTC ( #902997=note: print w/replies, xml ) Need Help??


in reply to Re^2: Reconcile one list against another
in thread Reconcile one list against another

Here's a simple way to take the difference of sets.
use Data::Dumper; %one = ( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6,); %two = ( 'a' => -1, 'e' => -2, 'i' => -3, 'o' => -4, 'u' => -5,); print Dumper(\%one, \%two); %tmp = %one; delete @tmp{keys %two}; print Dumper(\%tmp); %tmp = %two; delete @tmp{keys %one}; print Dumper(\%tmp);
Running the above produces the following:
$VAR1 = { 'e' => 5, 'c' => 3, 'a' => 1, 'b' => 2, 'd' => 4, 'f' => 6 }; $VAR2 = { 'e' => -2, 'u' => -5, 'a' => -1, 'o' => -4, 'i' => -3 }; $VAR1 = { 'c' => 3, 'b' => 2, 'd' => 4, 'f' => 6 }; $VAR1 = { 'u' => -5, 'i' => -3, 'o' => -4 };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://902997]
help
Chatterbox?
[atcroft]: PriNet: Those code bits worked for me, with test hashes, but I didn't test it with more than a few simple test cases. *shrug* Had hoped it would help, at least.
[PriNet]: i think i found the problem, the "source" array that sets the individual key values isn't being cleared, it's keeping the previous values...
[atcroft]: PriNet: You might consider posting a small, self-contained snippet of that segment of your code, and see if someone else has a better idea.....

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-06-28 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (619 votes). Check out past polls.