in reply to Word incidence count

I'd probably do
my %counts; while (<>) { $counts{$_}++ for split; } print "$_: $counts{$_}\n" for sort keys %counts;

Replies are listed 'Best First'.
Re^2: Word incidence count
by holli (Abbot) on May 17, 2005 at 07:50 UTC
    That leaves all the punctuation and other non-word characters and will tamper the results. (e.g. counting "word" and "word," as two different entities.)


    holli, /regexed monk/
Re^2: Word incidence count
by mrborisguy (Hermit) on May 17, 2005 at 13:31 UTC
    how about this then? it splits on any non-word character, and takes acount for case.
    my %counts; while (<>) { $counts{ lc $_ }++ for split /\W+/; } print "$_: $counts{$_}\n" for sort keys %counts;