Re: simple rpn desktop calculator

[email protected] (PerlDiscuss - Perl Newsgroups and mailing lists)
Newsgroups gmane.comp.lang.perl.fun
Organization PerlDiscuss.com
Message-ID <[email protected]>
Chris Dolan wrote:

> A simplified version and an equivalent, first-draft Golfed version:

> #!/usr/bin/perl -w
> use Math::RPN;
> $| = 1;
> while ($_="@ARGV" || <>) {
>     @stack = rpn @stack, split;
>     last if @stack && $stack[-1] =~ /^q/i;
>     print "@stack ";
>     print("n"),last if @ARGV;
> }

> #!perl
> use  
> Math::RPN;$|=1;1while($_="@ARGV"||<>)&&!((@s=rpn@s,split)&&$s[-1]=~/^q/ 
> i||print("@s ")&&@ARGV&&print($/))

> Chris

> On Thursday, August 14, 2003, at 07:52  AM, Bennett Todd wrote:

> > I love this list.
> >
> > Jonathan Paton mentioned Math::RPN; I hadn't heard about that one.
> > My favourite little handy rpn desktop calculator just got a whole
> > lot simpler:
> >
> > 	#!/usr/bin/perl -w
> > 	use Math::RPN;
> >
> > 	if (@ARGV) {
> > 	    print for rpn map { split } @ARGV;
> > 	    print "n";
> > 	    exit 0;
> > 	}
> >
> > 	$| = 1;
> > 	my @stack;
> > 	while (<>) {
> > 	    @stack = rpn(@stack, split);
> > 	    exit 0 if @stack and $stack[-1] =~ /^q/i;
> > 	    print "@stack ";
> > 	}
> >
> > -Bennett
> > X5O!P%@AP[4PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
> > <mime-attachment>
> --
> Chris Dolan, Software Developer, Clotho Advanced Media Inc.
> [email protected], 294-7900, 211 S Paterson, Madison WI 53703
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.