| Open a text editor, for example, NotePad, and enter | | | | Save the script as interest.pl. Make a note of the |
| the following lines of code: | | | | directory/folder where you have saved it. |
| #!/usr/bin/perl -wprint "Monthly deposit: "; # prompt for | | | | Running the script |
| input | | | | You need to run the script from a command line |
| $deposit=; # get input from keyboardchomp $deposit; | | | | prompt, so open a terminal window/MS-DOS prompt. |
| # remove the newline character from the end of the | | | | Change to the directory/folder where the interest.pl file |
| variableprint "Interest rate (3, 4, 5.5, etc): "; # prompt for | | | | is located, and type the following command:perl |
| input | | | | interest.pl |
| $interest=; # get input from keyboardchomp $interest; | | | | When prompted, enter the monthly deposit, interest |
| # remove the newline character from the end of the | | | | rate, and the number of months that the money is |
| variable | | | | deposited. |
| # Change interest from 3, 4, 5, etc to .03, .04, .05, etc | | | | Error messages |
| $interest=$interest*.01; | | | | If the script did not work, you probably received one of |
| # Change interest to a monthly multiplier | | | | the following error messages: |
| $interest=$interest/12;print "No of months: "; # prompt | | | | - 'Bad command or filename' or 'command not found'. |
| for input | | | | This means that Perl has not been added to the |
| $nMonths=; # get input from keyboardchomp | | | | PATH variable. See your operating system help |
| $nMonths; # remove the newline character from the | | | | documentation for information on how to fix this |
| end of the variable | | | | problem. |
| # The interest calculation | | | | - 'Can't open perl script interest.pl: A file or directory |
| $total=$deposit * (((1 + $interest) ** $nMonths) -1 ) / | | | | does not exist'. This probably means that you are not |
| $interest;print "After $nMonths months you will have a | | | | in the folder/directory where you saved the script, in |
| total amount of $total"; | | | | which case you should change to the correct location. |
| (Note: the spaces on either side of STDIN are for | | | | - If you get a syntax error, it probably means you |
| display purposes only in this article. In your script, you | | | | have mis-typed the contents of the file. Open the file |
| can omit them.) | | | | and fix any mistakes. |