http://qs1969.pair.com?node_id=302505


in reply to Re: Re: Re: Help on array element counting
in thread Help on array element counting

This is a more 'perl baby-talk' version of monktim's code, in which he exploits several perl idioms which you may not be familiar with (yet!):

my %fruit_counts; foreach my $fruit(@fruit_list) { $fruit_counts{$fruit} = $fruit_counts{$fruit} + 1; #lhand for '++' } foreach my $fruit(keys %fruit_counts) { print "$fruit => ", $fruit_counts{$fruit}, "\n"; }

This is one of the neatest things about Perl! monktim's code and mine look very different but are very similar in an elemental sense.