#!/usr/imports/bin/perl use English; # Change this value to select which solution to run $choice = 1; if ($choice == 1) { #ex_02-1 #Learning Perl Appendix A, Exercise 2.1 $pi = 3.141592654; $result = 2 * $pi * 12.5; print "radius 12.5 is circumference $result\n"; } if ($choice == 2) { #ex_02-2 #Learning Perl Appendix A, Exercise 2.2 print "What is the radius: "; chomp($radius = ); $pi = 3.141592654; $result = 2 * $pi * $radius; print "radius $radius is circumference $result\n"; } if ($choice == 3) { #ex_02-3 #Learning Perl Appendix A, Exercise 2.3 print "First number: "; chomp($a = ); print "Second number: "; chomp($b = ); $c = $a * $b; print "Answer is $c.\n"; } if ($choice == 4) { #ex_02-4 #Learning Perl Appendix A, Exercise 2.4 print "String: "; $a = ; print "Number of times: "; chomp($b = ); $c = $a x $b; print "The result is:\n$c"; } if ($choice == 5) { #ex_03-3 #Learning Perl Appendix A, Exercise 3.3 srand; print "Enter list of strings (end with control-D): "; @b = ; $random_index = rand(@b); print "Answer: $b[$random_index]\n"; } if ($choice == 6) { #ex_03-3 #Learning Perl Appendix A, Exercise 3.3, alternative solution srand; print "Enter list of strings (end with control-D): "; while ($line = ) { chomp($line); push @b, $line; } $random_index = rand(@b); print "Answer: $b[$random_index]\n"; } if ($choice == 7) { #ex_04-2 #Learning Perl Appendix A, Exercise 4.2 print "What temperature is it? "; chomp($temperature = ); if ($temperature > 75) { print "Too hot!\n"; } elsif ($temperature < 68) { print "Too cold!\n"; } else { print "Just right!\n"; } } if ($choice == 8) { #ex_04-3 #Learning Perl Appendix A, Exercise 4.3 print "Enter a number (999 to quit): "; chomp($n = ); while ($n != 999) { $sum += $n; # Could also do: $sum = $sum + $n; print "Enter another number (999 to quit): "; chomp($n = ); } print "the sum is $sum\n"; }