Three variable scope declarators, three different behaviors (as recent as
5.7.2)
(Set One)
------------
$a = 'a';
{
my $a .= 'b', $a .= 'c' if $a .= 'd', $a .= 'e';
}
print $a, "\n"; # adec
$b = 'a';
{
local $b .= 'b', $b .= 'c' if $b .= 'd', $b .= 'e';
}
print $b, "\n"; # ade
$c = 'a';
{
my $c = 'f';
our $c .= 'b', $c .= 'c' if $c .= 'd', $c .= 'e';
}
print $c, "\n"; # adebc
(Set Two)
------------
$a = 'a';
{
$a .= 'b', $a .= 'c' if my $a .= 'd', $a .= 'e';
}
print $a, "\n"; # aebc
$b = 'a';
{
$b .= 'b', $b .= 'c' if local $b .= 'd', $b .= 'e';
}
print $b, "\n"; # a
$c = 'a';
{
my $c = 'f';
$c .= 'b', $c .= 'c' if our $c .= 'd', $c .= 'e';
}
print $c, "\n"; # ade
I'm sure this makes absolute sense under-the-hood, and it is documented
(sort of) to behave this way, but isn't it a tad too inconsistent, even for
Perl? (Particularly 'my' vs 'our'. 'local' makes sense with its current
behavior, but I'd personally rather it were consistent, too.)
--
Bryan C. Warnock
[EMAIL PROTECTED]