[EMAIL PROTECTED] writes:
: On Sunday 20 January 2002 21:00, Damian Conway wrote:
: > Bryan C. Warnock asked:
: > > Since the parentheses are no longer required, will the expressions
: > > lose or retain their own scope level?  (I'm assuming that whatever
: > > rule applies, it will hold true if you do elect to use parantheses
: > > anyway.)
: >
: > Err. Expressions don't have their own scope level, even in Perl 5.
: 
: They do in block conditional expressions.  Try this:
: 
:     #!/your/path/to/perl -w
:     my $x = 4;
: 
:     if (my $x = 5) {
:         print "$x\n";
:         my $x = 6;
:         print "$x\n";
:     } elsif (my $x = 7) {
:         print "$x\n";
:         my $x = 6;
:         print "$x\n";
:     } else {
:         print "$x\n";
:         my $x = 6;
:         print "$x\n";
:     }
: 
:     print "$x\n";     
: 
: "my" variable $x masks earlier declaration in same scope at Perl/demo.pl 
: line 9.   # the elsif masking the if
: Found = in conditional, should be == at Perl/demo.pl line 9.
: Found = in conditional, should be == at Perl/demo.pl line 5.
: 5
: 6
: 4

Compound statements in Perl 5 do have an implicit {} around the entire
statement, but that has nothing to do with the required parentheses
around the expressions, other than the fact that we're doing away with
both of those special rules in Perl 6.  But parentheses have always
been totally transparent to any C<my> contained within them.  It's
the implicit {} that was protecting the C<if> condition from getting
a warning like the C<elsif> got (which got the warning because it's
at the same scope level as C<if>'s declaration).

Larry

Reply via email to