in reply to Small Calculator!

A golf calculator? 29.

C:\test>perl -le"print eval while<>;" 2+2 4 3*5 15 $a=3**2+4 13 $a/2 6.5 (1+(2*3)+4)/($a%3) 11 ^Z C:\test>

Or with a Log10 function: 53. (Note: capital L)

C:\test>perl -le"sub Log{log(pop)/log(10)}print eval while<>;" Log(100) 2 10**2 100 Log(30)+log(40) 5.1660007088336 10**(Log(30)+Log(40)) 1200 exp(log(30)+log(40)) 1200

Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Replies are listed 'Best First'.
Re: Re: Small Calculator!
by John M. Dlugosz (Monsignor) on Oct 04, 2002 at 21:07 UTC
    The -l is just used to add a newline to each print?

    Why not use -p flag too, and have it do the reading and printing?

    perl -lpe"$_=eval"
    (works in a file, -e has issues under Windows)

      Adding some error checking...

      perl -ple'$_=eval||$@'

      A calculator really should be able to tell you not to divide by 0, don't you agree? :-)

      -sauoq
      "My two cents aren't worth a dime.";
      
        What if the result really is "false", e.g. zero?