# File: sub1.pl # Title: Asks for a number returns double. Use subroutine double(). # Do this until you want to. Continue(y/n)? = # Author: Mihaela Malita # Input a number? 5 # Double is 10 # Continue(y/n)? n # Bye $yesorno = 'y'; while ($yesorno eq 'y') { double(); # invoke subroutine double() print "\nI also know N: ",$n; #N is global print "\nContinue(y/n)? "; $yesorno = ; chop($yesorno); } print "Bye"; exit; # Subroutine: careful using Local vs Global variables. No local variables here sub double { print "\nInput a number? "; $n = ; chop($n); # N is global print "Double is ", $n * 2 ; #here prints result return; #does not return anything!! }