in reply to hard referencing in hashes?!?

Well, a) you can increment just about anything with the ++ operator.
And b) there's no need to see whether the element exists in the hash yet, because if you apply the ++ to a non-existent item, it treats it like it had the value of 0.

So:

foreach $word ( @words ) { $word_list{$word}++; }
That should do it. Perl makes the easy things easy!

Replies are listed 'Best First'.
Re: Re: hard referencing in hashes?!?
by ph0enix (Friar) on Nov 08, 2002 at 11:05 UTC
    map { $word_list{$_}++ } @words;
      $word_list{$_}++ for @words; @sorted = sort keys %word_list;
        @word_list{@words}=1; @sorted = sort keys %word_list;

        update:
        Oh come on, that shift+9 shift+0 ... 3 extra keys man ... *me*shakes*head* ... whatever happened to lazyness ???

        :D

        ____________________________________________________
        ** The Third rule of perl club is a statement of fact: pod is sexy.

        Thanks for all your help guys! I was wondering how I would be able to get word123 into my @word but not 456. So that word123 would be a word, but 456 isn't a word. Right now I have
        my @words = map {s/[.,!\W\?]\B//g; split; } <FILE>;
        With this i'm getting it to keep word123 but if its 39 it would remove the 3 but not the 9? Also if I add an i (case insensitive) behind the /g would that give me There = there?