In addition to the good replies above, this:
chomp(@words = <STDIN>); foreach $word (@words){ $count{$word}++ } # is better done like this: while( my $word = <STDIN> ){ chomp $word; $count{$word}++; }
As you can see, the second idiom doesn't require the @words array at all, since it reads and processes the data one line at a time. That doesn't matter much for small amounts of data, but for larger amounts the first method could run into memory constraints. It's best to use the second method by default unless you must use the first for some reason.
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re: 2 newby questions
by aaron_baugher
in thread 2 newby questions
by Socrates440
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |