Above, you have several good answers to turn in (this is homework, isn't it? If so, better to label it so there's no question about your integrity) but your original code suggests you'll benefit from some of the pointers in the comments below:

#!/usr/bin/perl use strict; # strict and warnings are your friends. USE THEM AL +WAYS! use warnings; # 923876 my $num; input(); # you need not dump all your functions into subs # and certainly not into chained subs, but using ch +ained subs # here makes it easier for me to point out a few th +ings =head print "\n Press any key to exit"; # Utterly unnecessary - # your program will exit when it run +s out of $key = <STDIN>; # instructions, absent code to speci +fically do # otherwise ... such as sub quit_or_ +repeat: #End of Program =cut sub input { print "Enter an integer that is between 0 and 9: "; # no newline +so user can chomp ($num = <STDIN>); # enter data +at prompt test_input(); } sub test_input { if ( $num =~ /^[1-8]$/ ) { # 1...8 are the numbers "between 0 an +d 9" # as spec'ed by the prompt in OP's co +de main(); } else { print "Only single-digit, positive integers, 1 - 8, are allowe +d\n"; input(); } } sub main { for(my $i=1; $i<=$num; $i++) { print "$i "; } print "\n"; quit_or_repeat(); # sub called here actually does something # contrast w/ the original "$key = <STDIN> # # End of Program" + } sub quit_or_repeat { my $key = ''; print "\n Press 'q' to quit or any other key to continue: "; chomp ($key = <STDIN>); if ( lc($key) eq 'q' ) { # either 'q' or "Q" quits exit; } else { input(); # go another round } }

In reply to Re: force user to only enter numbers by ww
in thread force user to only enter numbers by Anonymous Monk

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.