Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by mr_mischief (Monsignor)
on Jul 01, 2009 at 00:38 UTC ( [id://776220]=note: print w/replies, xml ) Need Help??


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

I borrowed your idea and made something short and very ugly which does the whole job including percentages and total. I even added a count of distinct characters:
++$t,++$c{$_}for map/\w/g,<>; print$_,"\t",$c{$_},"\t",$c{$_}/$t*100,$/for sort keys %c; print"Distinct: ".keys(%c)."\tTotal: $t\n";

I doubt I'd call that an "improvement", at least with a straight face. It could be cleaned up pretty easily, though.

Replies are listed 'Best First'.
Re^4: Golf: Improve this guy's fail . . . please!
by shmem (Chancellor) on Jul 01, 2009 at 00:43 UTC
    It could be cleaned up pretty easily, though.

    Then do it! No good leaving lousy code floating around... ;-)

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found