<< Back
Subroutines
Calling
- Do not use '&' when calling subroutines. Using '&' modifies how the
arguments are passed into the subroutine and can cause strange problems.
- Use parenthesis when calling user-defined subroutines. Parenthesis are not required
when calling core functions.
- When calling the open and split builtins, use the three argument variants.
open my $file, "<", "/path/to/file" or die "Error! $@";
close $file;
my ($var1, $var2, $var3) = split /:/, $variable, 3;
my $result = get_data( $param1, $param2 );
Defining
- Unpack '@_' first. Then check the variables for definedness.
- return explicitly.
sub get_data {
my ($param1, $param2) = @_;
if (not defined $param1 or not defined $param2) {
die "Error: required arguments not found!";
}
return $value;
}
Copyright © 2009 Yet another bulletin Board. All rights reserved.