in reply to Newbie Q:How do I compare items within a string?
FYI, if you don't need to preserve the order than the array is unneccessary (just use the hash) and that would make it a frequently asked question.my @words; # Defined elsewhere my %uniq; ++$uniq{$_} for @words; for my $word (@words) { if (exists $uniq{$word}) { print "Word: $word\tCount: $uniq{$word}\n"; delete $uniq{$word}; } }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Newbie Q:How do I compare items within a string?
by PerlGrrl (Sexton) on May 07, 2006 at 13:25 UTC | |
by Limbic~Region (Chancellor) on May 07, 2006 at 13:29 UTC | |
by ww (Archbishop) on May 08, 2006 at 15:56 UTC |