# File: sub5.pl # Title: Use subroutine double() with parameters # Asks for a number returns double. Do this until you want to. # Author: Mihaela Malita # Input a number? 5 # Double is 10 # Continue(y/n)? n # Bye $yesorno = 'y'; while($yesorno eq 'y') { print "Input a number? "; $n = ; # read $n print "Double is " ,double($n); # invokes subroutine double($n) print "\nContinue(y/n)? "; $yesorno = ; chop($yesorno); } print "Bye"; exit; ########## arguments are in an array called @_ sub double { my($x) = @_; # $x is a local PARAMETER takes value of $n return $x * 2; # result is computed and returned }