Questions about this topic? Sign up to ask in the talk tab.
Perl/Basics/User Defined Functions
From NetSec
Revision as of 03:18, 16 July 2012 by AlizaLorenzo (Talk | contribs) (Created page with "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 sca...")
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(); |