#!/usr/bin/perl use strict; # https://www.perlmonks.org/?node_id=11154123 use warnings; use List::AllUtils qw( uniq_by ); open my $fh, '<', \<<END or die; nick 5 nick 10 nick 20 john 78 erik 9 erik 12 END my @firstofeachname = uniq_by { (split)[0] } <$fh>; print @firstofeachname;
Outputs:
nick 5 john 78 erik 9
In reply to Re: How can I keep the first occurrence from duplicated strings?
by tybalt89
in thread How can I keep the first occurrence from duplicated strings?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |