in reply to Storing unique values
#!/perl/bin/perl use warnings; use strict; my @arr = qw(AB1 BX6 WF2 CB7 EZ6 WY2 AB1 AB1 WF2 ET9); my $hash = {}; for my $cur (@arr) { if (exists($hash->{$cur})) { $hash->{$cur}++; } else { $hash->{$cur} = 1; } } my @unique = sort keys %$hash; for (@unique) { print sprintf qq(Value "%s" occurred %d times.\n), $_, $hash->{$_}; }
As you parse through the source array, you can just check for existence in the %$hash, and then process/ignore as necessary.
Where do you want *them* to go today?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Storing unique values
by Aristotle (Chancellor) on Jan 18, 2003 at 20:28 UTC |