<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all,
>
Hello,
> If I have a file that has ...
>
> A
> A
> B
> C
> D
> D
> D
> E
> E
> F
> F
> G
>
> How do I remove the duplicates via a Perl script?
perldoc -q "How can I remove duplicate elements from a list or array"
One way to do it:
#!/usr/bin/perl
use strict;
use warnings;
my @array = ();
my %hash = ();
while(<DATA>) {
s/\s+//;
$hash{$_} = 1;
}
@array = sort keys %hash;
__DATA__
A
A
B
C
D
D
D
E
E
F
F
G
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>