develooper Front page | perl.perl6.language | Postings from May 2004

Re: C style conditional statements

Thread Previous | Thread Next
=?iso-8859-1?Q?St=E9phane?= Payrard
May 12, 2004 01:37
Re: C style conditional statements
Message ID:
Le Wed, May 12, 2004 at 02:00:42AM +0200, le valeureux mongueur Pedro Larroy a dit:
> Hi
> Is there any chance that in perl6 there will be the possibility to write
> if/else statements without {}s with the condition at the beginning?
> Like 
> if (condition)
> 	statement;
> In order not to break traditional C culture. Is there any technical
> reason why it wasn't done in perl5? 

In Perl5, variable declaration are an executable statement. Also the
scope of a variable starts from its declaration and ends at the
end of the immediately enclosing block. Things would get
problematic if the branches of an if/else were not scoped.
What would be the meaning of :

if (condition)
   my $foo = 'bar';
   print $foo;

Now about  the syntax, it is not clear if the statement before
the 'else' can/must be semicolon terminated.

A similar example of stange meshing of scope and flow of control in
perl5 is:

   my $foo = $bar if $buz;

I can't even remember what it supposed to do when it is in a loop
where $bar and $buz change. And I would bet that the exact
semantic is not even documented in most books.


> Regards.
> -- 
> Pedro Larroy Tovar | Linux & Network consultant | 
> Software patents are a threat to innovation in Europe please check: 

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About