See Appendix A for answers.
Write a program that asks for the temperature outside, and prints “too hot” if the temperature is above 72, and “too cold” otherwise.
Modify the program from the previous exercise so that it prints “too hot” if the temperature is above 75, “too cold” if the temperature is below 68, and “just right!” if it is between 68 and 75.
Write a program that reads a list of numbers (on separate lines) until the number
999
is read, and then prints the total of all the numbers added together. (Be sure not to add in the999
!) For example, if you enter1
,2
,3
, and999
, the program should reply with the answer of6
(1+2+3
).Write a program that reads in a list of strings on separate lines and then prints out the list of strings in reverse order—without using
reverse
on the list. (Recall that<STDIN>
will read a list of strings on separate lines when used in an array context.)Write a program that prints a table of numbers and their squares from to 32. Try to come up with a way in which you don’t need to have all the numbers from to 32 in a list, and then try a way in which you do. (For nice looking output,
printf "%5g %8g\n", $a, $b
prints
$a
as a five-column number and$b
as an eight-column number.)
Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.