O'Reilly logo

Learning Perl, Second Edition by Randal L. Schwartz, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.8. Exercises

See Appendix A for answers.

  1. Write a subroutine to take a numeric value from 1 to 9 as an argument and return the English name (such as one, two, or nine). If the value is out of range, return the original number as the name instead. Test it with some input data; you'll probably have to write some sort of code to call the subroutine. (Hint: the subroutine should not perform any I/O.)

  2. Taking the subroutine from the previous exercise, write a program to take two numbers and add them together, displaying the result as Two plus two equals four. (Don't forget to capitalize the initial word!)

  3. Extend the subroutine to return negative nine through negative one and zero. Try it in a program.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required