Questions about this topic? Sign up to ask in the talk tab.
Perl/Basics/User Defined Functions
From NetSec
A function is defined by the programmer to create re-usable code. In our example, we will make an is_integer function that returns either 1 or undef depending on whether the scalar passed is an integer or not.
sub is_integer { my $scalar = shift; return 1 if (int($scalar) == $scalar); return undef; } |
Usage:
print "This scalar is an integer.\n" if (defined is_integer($scalar)) else print "This is not an integer.\n"; |
return($scalar,@array); |
my ($scalar,@array) = function(); |