in reply to Hash problem - Perl noob
First off you don't need to put parens around your variables. And what is going wrong is you're trying to look up values from @phrase, when you don't need to. Here is how I would write this, following your style:
use strict; use warnings; my @phrase = ( 'apple', 'apple', 'banana', 'banana', pear', 'pear', 'kiwi', 'kiwi' ); my %wordfreq; # Here $i contains the actual value from @phrase foreach my $i ( @phrase ) { $wordfreq{$i}++; print "$i appears ", $wordfreq{$i}, "\n"; }
Frank Wiles <frank@revsys.com>
www.revsys.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash problem - Perl noob
by johngg (Canon) on Sep 15, 2006 at 19:09 UTC | |
by ides (Deacon) on Sep 18, 2006 at 13:29 UTC |