Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by patric (Acolyte)
on Apr 16, 2009 at 07:25 UTC ( [id://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). :( :( :(

Replies are listed 'Best First'.
Re^3: duplicates getting omitted while comparing values inside foreach.
by Corion (Patriarch) 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?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-03-29 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found