I have to make a perl calculator for my class that asks if the use wants to add or mutiply . and so far . this is the only this i have print " Now im going to add 2 numbers . \n" ; print " What 2 numbers do you want to add ?" ; print "\n" ; chomp( $firstnumber=<>) ; print "what is the second number you want to add ? \n " ; chomp( $secondnumber=<>) ; $result= $firstnumber + $secondnumber ; print "when you add firstnumber and $secondnumber the result is $ result \n" ; now i have to add a IF statement to the calculator and add multiplication to it . so can some one plz show me how to use a IF statements in perl . and accept the user when they tell me what they want to do...
Tizag on how to use IF statements. http://www.tizag.com/perlT/perlif.php Here's a quick modification. print "Enter m to multiply, any other key to add. \n"; chomp($operation = <>); print " What is the first number ?" ; print "\n" ; chomp( $firstnumber=<>) ; print "Enter second number? \n " ; chomp( $secondnumber=<>) ; if ($operation eq "m") { $result = $firstnumber * $secondnumber; $operation_text = '*'; } else { $result= $firstnumber + $secondnumber ; $operation_text = '+'; } print "$firstnumber $operation_text $secondnumber = $result";
And one more question . i only used perl at school and we open it with " perl command line interpreter " does any1 know where i can get it
http://www.activestate.com/ Download activeperl, you will have to setup the path information and run it from a command line.
This it the direct download, just pick your OS and you're set. http://www.activestate.com/store/download.aspx?prdGUID=81fbce82-6bd5-49bc-a915-08d58c2648ca
I don't know what you downloaded, but the two packages for windows are either a MSI or a ZIP file. http://www.activestate.com/store/download.aspx?prdGUID=81fbce82-6bd5-49bc-a915-08d58c2648ca MSI is the windows installer version, the AS package is a zip archive. I would recommend the MSI.
use the MSI. http://www.activestate.com/store/download_file.aspx?binGUID=0e991cbb-7482-4900-88b0-4218add83d01