in reply to Re^2: guidelines for inline coding
in thread guidelines for inline coding
I agree that all my three examples are somewhat simplistic, I just wanted to convey the idea of the syntax that the OP was apparently looking for. In the third case, it is true that if print fails, the next statement will not be executed and the next line of code will be executed, which is presumably not what you want. But, OTOH, if the print statement fails, we have much deeper trouble than this possible Heisenbug, so that the random bug is really not the major concern.
Having said that, I fully agree that the do_some_statement() and do_some_other_statement() if something_is_true is nice for writing concise code, but can be dangerous if you are not cautious enough.
I once made the mistake of writing some code basically looking like that:
That worked perfectly for most of the cases, except the first time when an error occurs through the loop, because $nb_errors was false (either 0 or undef) the first time through the loop. Changing it to:$nb_errors++ and next if some_condition(); # wrong, don't do it
is sufficient to correct the issue. But it shows that such a construct can be dangerous and must be carefully considered.++$nb_errors and next if some_condition();
|
|---|