Mark Berryman wrote:

Could someone please explain to me why only the last two expressions
return correct results?

$ perl -e "print (212-32)*5/9;"
180
$ perl -e "print (212-32)*5;"
180
$ perl -e "print (212-32);"
180
$ perl -e "print 5*(212-32)/9;"
100

There was just a long discussion on perl5porters about this. You are implicitely calling print as a function in the first three cases, so you are effectively calling


(print(212-32))*5/9;

to take just the first example. Try this instead:

        $ perl -e "print +(212-32)*5/9;"
        100

If you had use '-w' you would have seen the warning

        $ perl -we "print (212-32)*5/9;"
        print (...) interpreted as function at -e line 1.
        Useless use of division (/) in void context at -e line 1.
        180

HTH

John

--
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4501 Forbes Boulevard
Suite H
Lanham, MD  20706
301-459-3366 x.5010
fax 301-429-5748




Reply via email to