I encountered a strange bug while using @_ to pass a single argument to a Perl subroutine. The value passed to a subroutine changes right after entering the subroutine.
Code example:
my $my_def = 0;
print "my_def = $my_def \n";
@someResult = doSomething($my_def);
sub doSomething {
my $def = @_;
print "def = $def \n";
...
}
This returned:
> my_def = 0
> def = 1 # instead of "0"
One more strange thing is that the code worked right for several months before.
The problem was resolved, when I changed it to:
sub doSomething {
my $def = $_[0];
Could anyone tell what could cause the problem? Are there any limitations in using @_ to pass a single argument?
Thanks!