in reply to How can I keep the first occurrence from duplicated strings?
many variations but at glance it seems to me that this is missing: use a hash and put vualues into an array (choroba suggested this..).
Being an opportunity to produce a oneliner, I cannot resist to :)
cat uniqfirst.txt nick 5 nick 10 nick 20 john 78 erik 9 erik 12 perl -lanE "push@{$r{$F[0]}},$F[1]}{say join' ',$_,$r{$_}[0]for keys%r +" uniqfirst.txt erik 9 nick 5 john 78 perl -MO=Deparse -lanE "push@{$r{$F[0]}},$F[1]}{say join' ',$_,$r{$_}[ +0]for keys%r" BEGIN { $/ = "\n"; $\ = "\n"; } use feature 'current_sub', 'evalbytes', 'fc', 'postderef_qq', 'say', ' +state', 'switch', 'unicode_strings', 'unicode_eval'; LINE: while (defined($_ = readline ARGV)) { chomp $_; our @F = split(' ', $_, 0); push @{$r{$F[0]};}, $F[1]; } { say join(' ', $_, $r{$_}[0]) foreach (keys %r); } -e syntax OK
L*
|
|---|