To remove duplicates, the best way is to use List::MoreUtils's uniq
,:
use List::MoreUtils 'uniq';
my @unique_list = uniq @list;
or without CPAN (although this is rarely necessary):
my %values;
@values{@list} = ();
my @unique_list = keys %values;
You can sort any list using the built-in function sort -- see perldoc -f sort and perldoc -q 'How do I sort an array'.
Incidentally, the data you have quoted does not match the behaviour you are describing. If you declare an array as
@uniqarr = qw(error 0 goodrecordno:6123, error 0 goodrecordno:6143, error 1 goodrecordno:10245, error 1 goodrecordno:10678, error 1 goodrecordno:10698, error 2 goodrecordno:16245, error 2 goodrecordno:16123);
...then its content will contain:
(
'error',
'0',
'goodrecordno:6123,',
'error',
'0',
'goodrecordno:6143,',
'error',
'1',
'goodrecordno:10245,',
'error',
'1',
'goodrecordno:10678,',
'error',
'1',
'goodrecordno:10698,',
'error',
'2',
'goodrecordno:16245,',
'error',
'2',
'goodrecordno:16123'
);
What you need to do is read in the data into a hash table, then parse according to your criteria. I cannot go further as it is not at all clear what you are looking for. Please read perldoc perldata and perldoc perldsc to learn more about Perl data structures.