Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 lurking in the Monastery: (8)
As of 2014-12-19 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls