in reply to Syntax trouble?

Hello IISGUY,
A few suggestions in addition to what's been said:

  1. Check out perlsyn in the Perl documentation. You should get in the habit of adding the following to the top of your scripts:
    use strict; use warnings; use diagnostics; use Data::Dumper;
    The first two pragmas (use strict; use warnings) are *musts. The second two items *(use diagnostics; use Data::Dumper;) will give you additional information on any errors your script may be returning.

  2. Declare your variables (you will get an error if you do not add my):
    my $num1=$ARGV[0]; my $num2=$ARGV[1];
  3. Everyone has their own approach to solving a problem but why not be direct and test for the correct answer first instead of testing for incorrect input. Here's one pseudo-ish approach:
    # 1 # Ask the user for two numbers # 2 # while the first number is less than the second; # add 1 to the first number # then print out the second #^# THAT'S THE CONDITION YOU WANT #^# #3 #v# NOW DESCRIBE WHAT CAN GO WRONG AND WHAT TO DO ABOUT IT #v# # if the user enters less than two numbers # say to the user: "you didn't give me two numbers" # if the user enters more than two numbers # say to the user: "you gave me too many numbers

I hope this helps. Good luck!

  1. If you're using Perl version 5.012 or 5.014 these are included by default
  2. Read up on Data::Dumper for more information on what it does and how to use it.

Update 04:07:24 PM -0400 on Saturday, 5/28/11: added notes on later Perl versions and Data::Dumper.


"...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote