Subject: | undefined behaviour of 'my' variables with conditional |
The use of 'my' with a conditional execution is undefined:
sub get {
my($self,$remote) = splice(@_,0,2);
Show quoted text
> my $local = shift if @_ % 2;
my %arg = ( %$self, @_ );
See perlsyn:
NOTE: The behaviour of a "my" statement modified with a statement
modifier conditional or loop construct (e.g. "my $x if ...") is
undefined. The value of the "my" variable may be "undef", any
previously assigned value, or possibly anything else. Don't rely on
it. Future versions of perl might do something different from the
version of perl you try it out on. Here be dragons.
This code should be changed to make the conditional on variable assignment not declaration (or use a ternary operation, or similer).