[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] inscrutable code formatting (was 100 point words)



Said Rich Morin <rdm@cfcl.com>:
>submissions.  Nonetheless, _I_ would appreciate it if authors
>would include expanded versions of this genre of code, as:
>
>   perl -ne'$t=0;$t+=ord(uc)-64 for split//;$t-46||print'
>
>   perl -ne '
>     $t =  0;
>     $t += ord(uc) - 64 for split //;
>     $t -  46 || print
>   '

That's why O::Deparse is cool:

% perl -MO=Deparse -ne '$t=0;$t+=ord(uc)-64 for split//;$t-46||print'
-e syntax OK
LINE: while (defined($_ = <ARGV>)) {
    $t = 0;
    foreach $_ (split(//, $_, 0)) {
        $t += ord(uc $_) - 64;
    }
    print $_ unless $t - 46;
}

OBfun:

perl -ne '
 BEGIN { $s{$_} = $s{uc($_)} = sprintf("%-2d+", ++$i) foreach ("a".."z"); }
 ($m=$_) =~ s/(.)/$s{$1}/g;
 print unless (eval "$m-100");'


-- 
Greg Fast 
Illinois Mathematics and Science Academy
1500 W. Sullivan Rd, Aurora, IL 60506
630.907.5995

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe