When calling a subroutine with the "&" sigil prefix and no parenthesis, the current @_
array gets implicitely passed to the subroutine being called. This can cause subtly odd
behaviour if you are not expecting it.
sub second_level {
print Dumper \@_;
}
sub first_level {
# using '&' sigil and no parens.
# doesn't look like I'm passing any params
# but perl will pass @_ implicitely.
&second_level;
}
first_level(1,2,3);
> $VAR1 = [
> 1,
> 2,
> 3
> ];
No comments:
Post a Comment