ok... Here is my edit...
#!/usr/local/bin/perl -w use strict; srand; guess_routine(); #moved the print and rand into the routine # that way you don't have the code duplicated when user # says y for new game... sub guess_routine { my @guesses; print "I have a number between 1 and 19.\nTry to guess it.\n"; my $numb=int(rand(20)); my $in = input(); while ($in != $numb){ print($in > $numb ? 'Too high! ' : 'Too low! '); # moved to trinary operator, just shrinks up # code, if else isn't bad @guesses = sort{$a <=> $b} (@guesses,$in); # you were pushing onto the array, then sorting # simply sorting array and value together shoule # be more efficient $in = input(\@guesses); # created a subroutine for # this, since you had similar code in two places. } print "\nYes, $numb is the number!\n"; print "So you want another go?\n"; my $answer=<STDIN>; # no chomp, you check /^y/ chomp unecessary if ($answer =~/^y/i){ guess_routine(); } else { print "\nOK, bugger off then!\n"; exit 0; } } sub input { my $in; print "\nSo far you've guessed @{$_[0]}." if $_[0]; print "\nWhat is your guess?\n"; $in=<STDIN>; chomp ($in); $in }

                - Ant
                - Some of my best work - Fish Dinner


In reply to Re: Reading an array with a single value (My 2nd completed script!) by suaveant
in thread Reading an array with a single value (My 2nd completed script!) by jerrygarciuh

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.