note
vitoco
<p>Well, without reading the explanation for the warning, I would expect <c>()(BBB)()</c> or <c>(AAA)(BBB)(AAA)</c> or just <c>()()()</c> like the case of no parameters.</p>
<p>It seems that <c>sub f</c> (the second one) <i>compiles</i> in runtime, and internal <c>$a</c> is not asigned the first time it is called, but when called from <c>g</c>, it glues the first value it receives.</p>
<p>Let me show an improved example:</p>
<code>
#!perl
use v5.10;
use strict;
use warnings;
my $a = shift;
sub f {
say "global f ($a)";
}
f();
sub g {
my ($a) = @_;
say "global g ($a)";
sub f {
say "local f ($a)"; # line 17
}
f();
}
f();
g(shift);
say "main1 $a";
$a = shift;
say "main2 $a";
f();
g(shift);
f();
__END__
C:\Temp>localsub.pl AAA BBB CCC DDD
Variable "$a" will not stay shared at C:\Temp\localsub.pl line 17.
Subroutine f redefined at C:\Temp\localsub.pl line 16.
Use of uninitialized value $a in concatenation (.) or string at C:\Temp\localsub.pl line 17.
local f ()
Use of uninitialized value $a in concatenation (.) or string at C:\Temp\localsub.pl line 17.
local f ()
global g (BBB)
local f (BBB)
main1 AAA
main2 CCC
local f (BBB)
global g (DDD)
local f (BBB)
local f (BBB)
</code>
<p>As you can see, the internal variable is empty (uninitialized) the first two times <c>f</c> is called, but as soon as it is defined, it keeps that value forever. Weird...</p>
809000
809128