in reply to Newbie Q:How do I compare items within a string?

PerlGrrl,
Welcome to the Monastery. Let's assume for a second that the reason you used an array is because you want to preserve order. You can use a disposable hash to find the unique counts.
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}; } }
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.

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
    Thnx! You've helped heaps...Unfortunately, preserving order is important, as is matching across mixed case...I guess that's why I was having so much trouble. I knew I had to use a hash, I just wasn't sure how. And thanks for the welcome - will try not to wear it out...
      PerlGrrl,
      Well, to make it case insensitive, play around with lc.

      Cheers - L~R

      welcome, and though I've only seen it recommended once here recently, you might want to consider Tie::IxHash -- I did, where preserving order was crucial but a hash was the reasonable solution to avoid having to iterate across 2 arrays concurrently -- and it bailed me out nicely!