Yes, the nested if and elsif and else makes the code difficult to read and I
often get stuck trying to make sense of it all. For now, I will look to see
if I can move some bit and pieces to subroutines to improve readability.

Thanks guys
Mimi

-----Original Message-----
From: Jim Gibson [mailto:jimsgib...@gmail.com] 
Sent: 14 April 2010 01:36
To: beginners@perl.org
Subject: Re: Nested if and elsif and else

On 4/13/10 Tue  Apr 13, 2010  4:35 PM, "Mimi Cafe" <mimic...@googlemail.com>
scribbled:

> I think this will work, but is it elegant.?

Yes, it will work, and yes, it is elegant, as long as it encapsulates the
logic that is required by your program.

Be sure and watch your indenting, so you can mentally group the correct
branches together (you are a little off in your first 'else'). Also be sure
and put some comments for each conditional that explains what is happening
if it is not obvious (but don't just repeat what is in the condition).

Make sure the 'do this', 'do that', and 'do something else' are not too
long. If they are more than a few statements, use subroutines (with good
names).

> If (condition){
> 
>    if (nexted_condition){
> 
>       do this.
> 
>    }
> 
>    Elsif (nexted_condition){
> 
>       Do that... 
> 
>    }
> 
>   else{
> 
>     Do something else.
> 
>   }
> 
>  
> 
> }
> 
> else{
> 
>    Do something else..
> 
> } 



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to