Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Selective printing of the Duplicates

by Thomas Kennll (Acolyte)
on Jan 30, 2013 at 17:42 UTC ( #1016122=note: print w/ replies, xml ) Need Help??


in reply to Re: Selective printing of the Duplicates
in thread Selective printing of the Duplicates

I just put, the logic.. My code is a pretty big one, extracting from a DB and then trying to put it on a file. But, I'm stuck in this part of the logic wherein if I try to filter the duplicates always the 1st is picked the remaining is removed.. I wanted to know how can I ignore the 1st duplicate and pick the 2nd one..


Comment on Re^2: Selective printing of the Duplicates
Re^3: Selective printing of the Duplicates
by choroba (Abbot) on Jan 30, 2013 at 17:45 UTC
    If they are duplicates, how do you tell the 1st from the 2nd one?

    Anyway, if you use only a part of a line to find the duplicates, it makes sense. You can either reverse the input file and use the old algorithm, or you have to remember the last line seen for each key in a hash. The next problem of the latter is to get the original order of the lines.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: Selective printing of the Duplicates
by baxy77bax (Chaplain) on Jan 30, 2013 at 18:27 UTC
    Now is it the last one or the second one. Are these duplicates or multiplicities??

    So, given that these are repeated several times and you need the second one I would use :

    my %seen = (); my $tmp ... $seen{$_}++; if ($_ ne $tmp && $seen{$tmp} == 1){ print $_; $tmp =$_; }elsif ($_ eq $tmp){ print $_ if $seen{$_} == 2; }
    however if it is the last one then:
    my %seen = (); my $tmp; my $id; ... if ($_ ne $tmp){ $seen{$tmp}=$id++; } and then in the second loop: print $_ foreach (sort{$seen{$a}<=>$seen{$b}}keys %seen);
    baxy

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-14 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls