Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
sub g1 {
my $name = shift;
return "Hallo $name\n"
}
sub g2 {
my $name = shift;
return "Good Morning $name !\n"
}
my $name = "Joe";
my $greetings = "g1";
print &$greetings($name);
$greetings = "g2";
print &$greetings($name);
A subroutine may be called using an explicit & prefix. The & is optional in modern Perl, as are parentheses if the subroutine has been predeclared. The & is not optional when just naming the subroutine, such as when it's used as an argument to defined() or undef(). Nor is it optional when you want to do an indirect subroutine call with a subroutine name or reference using the &$subref() or &{$subref}() constructs, although the $subref->() notation solves that problem. See perlref for more about all that.