in reply to Re^2: Locate Unique values
in thread Locate Unique column from a given set of column
First off: always use strictures (use strict; use warnings;).
Second: you don't need to initialize arrays and hashes. Your declarations should look like:
my %seen; my @unique;
Avoid extra nesting. Refactor the loop as:
foreach my $item (@proc_name1) { next if $seen{$item}; $seen{$item} = 1; push (@uniq, $item); }
However, if you don't need to know the order that the items were seen then you don't need the array and can just:
my %seen; $seen{$_}++ for @proc_name1;
or using a hash slice you could:
my %seen; @seen{@proc_name1} = ();
In either case keys %seen gives the list of unique proc names.
|
|---|