Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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);

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2015-11-29 11:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls