my @cards = shuffle(@deck_of_cards); # No & necessary on &shuffle
Or if Perl's internal compiler has already seen the subroutine
definition, that's generally okay, too; in that case, you can
even omit the parentheses around the argument list:
sub division {
$_[0] / $_[1]; # Divide first param by second
}
my $quotient = division 355, 113; # Uses &division
This works because of the rule that parentheses may always be
omitted, except when doing so would change the meaning of the code.
But don't put that subroutine declaration
after the invocation, or the compiler
won't know what the attempted invocation of
division is all about. The compiler has to see the
definition before the invocation in order to use the subroutine call
as if it were a builtin.
That's not the catch, though. The catch is this: if the
subroutine has the same name as a Perl builtin, you
must use the ampersand to call it. With an
ampersand, you're sure to call the subroutine; without it, you
can get the subroutine only if there's no
builtin with the same name:
sub chomp {
print "Munch, munch!";
}
&chomp; # That ampersand is not optional!