note
japhy
Here's a bit of critique...
<c>
for $i (@phrase) {
$wordfreq{"$phrase[ $j ]"}++;
# print "$wordfreq{\"$phrase[ $j ]\"} appears $wordfreq{\"$phrase[ $j ]\"}\n";
$j++;
}
</c>
First, in each run of the loop over <c>@phrase</c>, <c>$i</c> holds the particular element, so you can be saying <c>$wordfreq{$i}++</c> instead of <c>$wordfreq{$phrase[$j]}</c>. Second, you're using quotes around <c>$phrase[$j]</c> that are totally unnecessary. Third, your (commented out) print statement probably should have looked like: <c>print "$i appears $wordfreq{$i} times\n";</c>.
<p>
As for your "trouble formatting the report", maybe you should print some newlines or something.
<c>
for my $word (keys %wordfreq) {
print "$word appears $wordfreq{$word} times\n";
}
</c>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-1936">
<hr/>
Jeff <tt><font color="#0000ff">[japhy]</font></tt> Pinyan,
[id://371157|P.L., P.M., P.O.D, X.S.]:
<a href="http://japhy.perlmonk.org/modules/">Perl</a>,
<a href="http://japhy.perlmonk.org/modules/Regexp-Parser/">regex</a>,
and <a href="http://lists.perl.org/showlist.cgi?name=perl5-porters"><tt>perl</tt></a>
<a href="http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=hacker">hacker</a>
<br>
<i>How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ <b>Meister Eckhart</b></i>
</div></div>
573191
573191