in reply to Re: Small Calculator!
in thread Small Calculator!

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)

Replies are listed 'Best First'.
Re: Re: Re: Small Calculator!
by sauoq (Abbot) on Oct 05, 2002 at 07:46 UTC

    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?

        Ouch. Right. That would probably be more important than error checking. How about:

        perl -ple'$_=eval||$@||0'
        -sauoq
        "My two cents aren't worth a dime.";