Whilst enjoying cholesterol rich victuals with fellow Perl coders, one boasted how he provided obfuscated solutions to new Perl coder's inquiries.

The case in point was providing the mean number from numbers, on sepearate lines of a file. Alledgedly, he produced a one-liner 40 characters long, using internal variables.

I enjoy obfuscation to learn more aspects of Perl but disapprove of making Perl code daunting to new coders. I set forth to best 40 characters. This is my attempt:

open I,'o';map{$a+=$_}<I>;print $a/$.

38 characters and yet too readable! Is there a more obscure and brief solution? I have faith that my fellow monks have knowledge to impart.


--
Brother Frankus.

Replies are listed 'Best First'.
RE (tilly) 1: Ars gratia artis.
by tilly (Archbishop) on Oct 04, 2000 at 15:37 UTC
    Use default variables and avoid abusing map:
    $t+=$_ for<>;print$t/$.
    23 characters.

    If adding the file to the code, use the poetry optimization:

    @ARGV=o;$t+=$_ for<>;print$t/$.
    leaves us at 31. With error handling if the file is not there! :-)

    PS: Your approach was nice. :-)

    EDIT
    Thanks Corion for catching a wrong closing code tag.

Latina gratia latinae.
by mdillon (Priest) on Oct 04, 2000 at 19:05 UTC
    using Latin is one way that is almost guaranteed to net ++ votes from me.