in reply to Re^3: Golf: Improve this guy's fail . . . please!
in thread Golf: Improve this guy's fail . . . please!
#!/usr/bin/perl -w use strict; use warnings; local $/ = undef; my $string = <>; my @array = split(//, $string); my %hash; foreach (@array) { if ($_ =~ /\w/) { $hash{$_}++; } } my @keys = sort keys %hash; my $total; foreach (values %hash) { $total += $_; } foreach (@keys) { printf "%s\t%d\t%.3f\n", $_, $hash{$_}, $hash{$_}/$total; } print "$total characters\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Golf: Improve this guy's fail . . . please!
by grinder (Bishop) on Jul 17, 2009 at 10:54 UTC | |
Re^5: Golf: Improve this guy's fail . . . please!
by Boldra (Curate) on Jul 23, 2009 at 09:34 UTC | |
Re^5: Golf: Improve this guy's fail . . . please!
by dragonchild (Archbishop) on Jul 29, 2009 at 02:42 UTC | |
by jwkrahn (Abbot) on Jul 29, 2009 at 02:52 UTC |