in reply to Simple command line calculator

Or you could just use Python or Ruby in interactive mode...

Replies are listed 'Best First'.
•Re: Re: Simple command line calculator
by merlyn (Sage) on Mar 14, 2002 at 20:17 UTC

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

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk
      

        How would you pass parameters to that expression?
        Rich36
        There's more than one way to screw it up...

        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

      The Perl debugger interface, to me, is too cluttered for this purpose, especially considering the -- what are they, ANSI control codes? -- formatting. Python's interactive mode is somewhat better, but Python doesn't do math quite as well as Perl, I think. Interactive Ruby (irb), out of the three, is IMHO the best; as two examples, Ruby automatically switches to bignums when necessary, and is not as whitespace-dependent as Python (important in interactive mode)... the major disadvantage is that it is much less common than Perl and Python, or so I've seen.

        The Perl debugger interface, to me, is too cluttered for this purpose, especially considering the -- what are they, ANSI control codes? -- formatting.

        ANSI codes, yes, because it's using Term::ReadLine::Gnu and Term::ReadLine (on my system at least) - i think they look cool, myself. (:

        of course, if you want an interactive calculator, the Term::Readline manual has a nice example.

        --
        strfry()