On Fri, 30 Aug 2002, Dharmendra Rai wrote:

The list FAQ requests folks to snip uneccessary lines before replying to 
mails. But surely the entire mail cannot be uneccessary. Please leave some 
parts of it so that other's in this list know what you are replying to.

> 
> my $ret_val;
> 
> my $i;
> 
> if ($#your_array < 0){
> 
> ## do appropriate thing
> 
> }
> 
> elsif ($#your_array == 0){ ## return the only value it has}
> 
> ## following is the ELSE part
> 
> for (my $i = 0; i < $#your_array; ++i)
> 
> {
> 
> $ret_val = your_array[i+1];

Do you test your code, this is a syntax error
$your_array[i+1];

> 
> $ret_val = your_array[i] if (your_array[i] > your_array[i+1]);

Same here. Use the ternary operator for this
$ret_val = ($your_array[i] > $your_array[i+1]) ? $your_array[i] : $your_array[i+1]; 
> 
> }
> 
> ## $ret_val contains the max number. 

This is C style coding, Felix had already posted a soln on similar lines.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to