Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: duplicates getting omitted while comparing values inside foreach.

by patric (Acolyte)
on Apr 16, 2009 at 07:25 UTC ( #757874=note: print w/replies, xml ) Need Help??


in reply to Re: duplicates getting omitted while comparing values inside foreach.
in thread duplicates getting omitted while comparing values inside foreach.

tried with DB_BTREE now, but still getting the same results(wrong one). :( :( :(
  • Comment on Re^2: duplicates getting omitted while comparing values inside foreach.

Replies are listed 'Best First'.
Re^3: duplicates getting omitted while comparing values inside foreach.
by Corion (Pope) on Apr 16, 2009 at 07:40 UTC

    I'm not sure what your code is supposed to do. But if you want to check whether one list is a subset of the other, possibly with duplicates, I recommend using a hash of array references and "colliding" the elements out:

    my %elements; # open left file while (<$left>) { chomp; # extract key my $key = $_; $elements{ $key } ||= []; push @{$elements{ $key }}, $_; }; # open right file while (<$right>) { chomp; # extract key my $key = $_; if (! exists $elements{ $key }) { print "Missing totally from left file: $_\n"; } else { my $match = shift @{$elements{ $key }}; print "Matched: $_ against $match\n"; if (0 == @{$elements{ $key }}) { delete $elements{ $key }; }; }; }; for (keys %elements) { print "Only in left file: @{ $elements{ $_ }}" };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2021-12-09 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?