#!/usr/local/bin/perl -w use strict; srand; print "I have a number between 1 and 19.\nTry to guess it.\n"; my $number=int(rand(20)); guess_routine($number); sub guess_routine { my @guesses; my $numb=$_[0]; print "Guess?\n"; my $in=; chomp ($in); print "You said $in is the number.\n"; while ($in != $numb){ if ($in > $numb) { print "Too high! "; }else{ print "Too low! "; } push (@guesses, $in); @guesses = sort{$a <=> $b} @guesses; print "\nSo far you've guessed @guesses."; print "\nWhat is your guess?\n"; $in=; chomp ($in); } print "\nYes, $numb is the number!\n"; print "So you want another go?\n"; chomp(my $answer=); if ($answer =~/^y/i){ @guesses=""; print "\nI have a new number between 1 and 19.\nTry to guess it.\n"; $number=int(rand(20)); guess_routine($number); }else{ print "\nOK, bugger off then!\n"; exit 0; } }