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

In reply to Re: Syntax trouble? by luis.roca
in thread Syntax trouble? by IISGUY

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.