in reply to Re: Hash problem - Perl noob
in thread Hash problem - Perl noob

Did you really mean to put your print statement in the foreach my $i ( @phrase ) { ... } loop? I think you are going to get eight lines of running total information like

apple appears 1 apple appears 2 banana appears 1 banana appears 2 pear appears 1 pear appears 2 kiwi appears 1 kiwi appears 2

rather than a summary of the word frequencies. To get a summary you could do something like

print qq{$_ appears $wordfreq{$_} times\n} for sort keys %wordfreq;

after the foreach loop.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: Hash problem - Perl noob
by ides (Deacon) on Sep 18, 2006 at 13:29 UTC

    Good catch! Sorry, was hurrying to finish up that post before I had to run out the door.

    Frank Wiles <frank@revsys.com>
    www.revsys.com