Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by perigrin (Sexton)
on Jul 01, 2009 at 04:52 UTC ( #776288=note: print w/ replies, xml ) Need Help??


in reply to Golf: Improve this guy's fail . . . please!

Following from a brain dump I made on IRC, and since nobody here seems to have looked at perl's command line switches:

#!/usr/bin/env perl -aF'' -nl
$t += @F; 
$c{$_}++ for @F; 
END { 
    printf("%s\t%d\t%.3f\n", $_, $c{$_}, $c{$_} / $t) for keys %c; 
    print "Total: $t" 
}
Of course the simplest solution from IRC was say `wc -c @ARGV`


Comment on Re: Golf: Improve this guy's fail . . . please!
Download Code
Re^2: Golf: Improve this guy's fail . . . please!
by grizzley (Chaplain) on Jul 01, 2009 at 08:15 UTC
    What about
    #!/usr/bin/env perl -n0 $t++,$c{$_}++ for /./g; printf("%s\t%d\t%.3f\n", $_, $c{$_}, $c{$_} / $t) for keys %c; print "Total: $t\n"
    ?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2015-07-03 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls