in reply to Perl Destroys Interview Question

What mr_mischief says, which can be fixed by replacement with $words{$_}++ for split; (no chomp needed). Also, I'd prefer an output loop which didn't construct a potentially long list of keys to iterate. Something like this,

while ($_ = each %words) { print $_, ';', $words{$_}, $/; }

I like to name my hashes singular for their values, not their keys. That makes the doc-suggested pronounciation work - $count('foo'} is "count of foo" and so on.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Perl Destroys Interview Question
by redsquirrel (Hermit) on Jan 13, 2004 at 15:13 UTC
    I agree, I like the name %count better than %words. The hash (Map) in my Java solution was named wordCount.