Example 12 - Function with arguments.


#!/usr/bin/perl
#*********************************************************
#     Example twelve - function with arguments.
#         by Al Bento
#*********************************************************

#define variables

   $f = 75;

#convert into celsius

     &convert($f, $celsius);

# print conversion results

    print " Fahrenheit Celsius\n";     # print header
    printf "%6d %8d\n", $f, $celsius;    # print the results

#*********************************************************

#sub definition

sub convert {
    $_[1] = 5/9 * ($_[0]-32);
}

download the script


This page is maintained by Al Bento who can be reached at abento@ubmail.ubalt.edu. This page was last updated on February 15, 2001. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.