in reply to •Re: Re: Simple command line calculator
in thread Simple command line calculator

perl -ple'$_=eval'
is a bit easier to use :)

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk

Replies are listed 'Best First'.
Re: Re: •Re: Re: Simple command line calculator
by Rich36 (Chaplain) on Mar 14, 2002 at 22:28 UTC
    How would you pass parameters to that expression?
    Rich36
    There's more than one way to screw it up...

      How would you pass parameters to that expression?

      2;130 juerd@ouranos:~$ perl -ple'$_=eval' 1+1 2 3*100 300

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk
      

Re: Re: •Re: Re: Simple command line calculator
by toku (Novice) on Mar 19, 2002 at 16:17 UTC
    You can make this take a command argument very easily. In fact you can replace the expr function with this:
    function calc { perl -ple '$_=eval' } function expr { echo "$1" | calc }
    Toku

      How about a Perl solution?

      perl -le'print eval shift'
      Or, to slurp all arguments:
      perl -le'print eval "@ARGV"'

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk