Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Selective printing of the Duplicates

by baxy77bax (Chaplain)
on Jan 30, 2013 at 18:27 UTC ( #1016131=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re^3: Selective printing of the Duplicates
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (20)
As of 2015-07-07 20:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls