develooper Front page | perl.perl6.language | Postings from August 2001

My, our, thems-over-theres.....

From:
Bryan C . Warnock
Date:
August 14, 2001 18:53
Subject:
My, our, thems-over-theres.....
Message ID:
01081421504804.01436@wakko.idiocity.nut
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
bwarnock@capita.com



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About