Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^5: Golf: Improve this guy's fail . . . please!

by mr_mischief (Monsignor)
on Jul 01, 2009 at 01:24 UTC ( #776231=note: print w/ replies, xml ) Need Help??

in reply to Re^4: Golf: Improve this guy's fail . . . please!
in thread Golf: Improve this guy's fail . . . please!

But... but... it's golf! ;-)

I guess adding a feature's not exactly in the spirit of golf, though. More golfed:

++$t,++$c{$_}for map/\w/g,<>; print$_,' ',$c{$_},' ',$c{$_}/$t*100,$/for sort keys%c; print"Total: $t\n"

So now that that's out of the way, how about still short but somewhat easier to read?

++$t, ++$c{$_} for map /\w/g, <>; for ( sort keys %c ) { $p = sprintf '%3.2f', $c{$_} / $t * 100; printf "%-5s%5d%7s%%\n", $_, $c{$_}, $p; } print 'Distinct: ' . (scalar keys %c) . "\tTotal: $t\n"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://776231]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2016-06-25 16:31 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (326 votes). Check out past polls.