Perl Subroutine aka function
A Perl function (subroutine) is a group of statements. In Perl you can use the terms: subroutine, method and function as you wish.
Define and Call a Subroutine
Perl defines a subroutine like this:
sub perl_subroutine_name{
body of ...
}
The typical way of calling that Perl subroutine is as follows ?
perl_subroutine_name( list of arguments );
Before Perl 5.0, the syntax for calling subroutines was different:
&subroutine_name( list of arguments );
The old style will work in the newest versions of Perl, but it is not recommended.
Example function definition:
#!/usr/bin/perl
sub perl_hello{
print "Hello, World!\n";
}
Example function call:
perl_hello();
Output:
Hello, World!
…
tags: & category: -