in reply to Next in IF statement question!

If next is present, you don't need elsif (can be just if) and last else can be plain code.
for (my $i = 0; $i < @{$mydata}; $i++) { $account_number = $mydata->[$i]{'account_number'} || ''; .... if($email eq '') { bad_email("No email address found '$account_number'."); next; } ... if(($name eq '') || ($account_number eq '')) { $msg = "Missing information: Number = '$account_number', Name = '$ +name'."; next; } # Send emails send_email( send my stuff here); ... exec_single_sql($sql, $db) || die "Unable to update table"; }

This is giving you less indentation and you don't have to worry about covering error cases in end code (email, SQL).

On the other hand, I've read Dijkstra arguing that multiple exit/repeat points make it more difficult to comprehend and analyse the loop.

-- Roman

Replies are listed 'Best First'.
Re^2: Next in IF statement question!
by pemungkah (Priest) on Nov 17, 2010 at 00:04 UTC
    next makes it harder (or impossible) to prove your program correct, and Djikstra was all about proof of correctness.

    I personally think the way next is employed can make a huge difference in readability and understandability. I would rather be able to say next if this; next if that; next if the_other; and then the rest of the loop; I find that much easier to understand.

    I don't care much whether I can prove it if I can read it.