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

Re: [FWP] Poor reverse polish calculator



On Sat, Mar 24, 2001 at 02:10:53PM +0000, Alisdair McDiarmid wrote:
> I wanted to try to implement a reverse polish calculator in 80
> characters, but in the end I couldn't get it any smaller than 120:
> 
> while(<>){for(split' '){if("+-*/"!~/([$_])/){push@k,$_;next;}
> ($O,$Z)=splice@k,-2;push@k,eval"$O$1$Z";}print pop@k,"\n";}
> 
> I know this code sucks and doesn't have any clever hacks in it, but
> can anyone write something functionally similar in eighty?


70 characters, including the command line options and the quotes:

  perl -pale'push@_,/\d/?$_:do{$_.=pop@_;eval pop(@_).$_}for@F;$_=pop@_'



Abigail

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