July 2002
Beginner to intermediate
432 pages
8h 55m
English
Suppose that you want to write a subroutine to compute the difference between two time values. Start your subroutine definition like this:
sub timediff($$) {The sub keyword signals the start of a subroutine. In this case, the subroutine is named timediff. The function takes two scalar parameters. This is indicated by the parameter list ($$).
The method Perl uses to pass parameters is unique: passing by special variable. When a function is called, Perl assigns the parameters to the array @_. You now need to get the parameters out of the @_ array and into something you can use.
One simple way of doing this is to use the shift function to “shift” the parameters out of @_ and into simple variables:
my $start_time = shift; # Time the ...
Read now
Unlock full access