Re: RFC 64 (v2) New pragma 'scope' to change Perl's default scoping

[email protected] (Tom Christiansen) Tue, 29 Aug 2000 19:58:01 -0600
Newsgroups perl.perl6.language.strict
Message-ID <23870.967600681@chthon>
>$x and $y are in the same scope. This is good, but also bad. For one
>thing, you can hang yourself real easily if you come from a C background
>and expect this to keep stuff private:

>   $x = 10;
>   sub square {
>      ($x) = @_;
>      $x *= $x;
>   }
>   $ans = square($x);
>   print "$x squared is $ans\n";  # "100 squared is 100" ?

>Ooops. What happened? Turns out the sub square()'s $x is the same $x as
>the one outside. Bad news, you reset the (global) value of $x. Ooops.

Perhaps you simply know inept C programmers.  In C, something that
isn't declared auto or static is going to be global.  Seeing no
scoping declarations, the C programmer who knows C will come to the
same conclusion as the Perl programmer, correctly understanding the
scope.

--tom