sub f {
# some code here
()
}
What does () mean in this Perl subroutine?
The last expression in a sub will be the return value. This ensures that (assuming no previous return
statements) the sub returns an empty list (rather then whatever was on the previous line of code).
OK ... so it is perhaps pathological, but this IS Perl we're talking about...
Depending on the actual text of "# some code here", it could conceivably produce a dereferenced CODE reference, in which case the parens would cause the CODE to be invoked with zero arguments, and the return value of that code would be the return value of `f'.
For example, the following will print out a single lowercase "a":
sub f {
&{sub { return $_[0] }}
(@_)
}
print f(qw( a b c d e f )), "\n";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With