Skip to main content
Became Hot Network Question
added 562 characters in body
Source Link
kjo
  • 16.4k
  • 25
  • 76
  • 125

I want to emphasize that the common response to all possible failures within the block (in this case, this response being a generic error message that does not distinguish among all the possible points of failure followed by termination) is an essential, non-negotiable aspect of this problem. In fact, I would argue that it is the aspect of the problem that makes being able to exit the code block from anywhere along it desirable.

IMPORTANT: In order to keep the example above easy to understand, the conditions are artificially simple. In practice, however, the evaluation of each condition may take up several lines of code! Please keep this in mind when you formulate your answer. The essential point of the example is that the code block can be exited from anywhere in the block.

EDIT: I added the "IMPORTANT: ..." clarification after the Perl example.

EDIT2: Emphasized the common response to all the failures within the block is an essential aspect of the problem.

IMPORTANT: In order to keep the example above easy to understand, the conditions are artificially simple. In practice, however, the evaluation of each condition may take up several lines of code! Please keep this in mind when you formulate your answer. The essential point of the example is that the code block can be exited from anywhere in the block.

EDIT: I added the "IMPORTANT: ..." clarification after the Perl example.

I want to emphasize that the common response to all possible failures within the block (in this case, this response being a generic error message that does not distinguish among all the possible points of failure followed by termination) is an essential, non-negotiable aspect of this problem. In fact, I would argue that it is the aspect of the problem that makes being able to exit the code block from anywhere along it desirable.

IMPORTANT: In order to keep the example above easy to understand, the conditions are artificially simple. In practice, however, the evaluation of each condition may take up several lines of code! Please keep this in mind when you formulate your answer. The essential point of the example is that the code block can be exited from anywhere in the block.

EDIT: I added the "IMPORTANT: ..." clarification after the Perl example.

EDIT2: Emphasized the common response to all the failures within the block is an essential aspect of the problem.

added 31 characters in body
Source Link
kjo
  • 16.4k
  • 25
  • 76
  • 125

IMPORTANT: In order to keep the example above easy to understand, the conditions are artificially simple. In practice, however, the evaluation of each condition may take up several lines of code! Please keep this in mind when you formulate your answer. The essential point of the example is that the code block can be exited from anywhere in the block.


I am looking for a good way to achieve this similar effect in a bash script.

1 It is likely that this quick, from-memory description oversimplifies somewhat...
2 In fact, with this approach, one could also dispense with the overall_status variable altogether, and test $? instead.

EDIT: I added the "IMPORTANT: ..." clarification after the Perl example.

I am looking for a good way to achieve this similar effect in a bash script.

1 It is likely that this quick, from-memory description oversimplifies somewhat...
2 In fact, with this approach, one could also dispense with the overall_status variable altogether, and test $? instead.

IMPORTANT: In order to keep the example above easy to understand, the conditions are artificially simple. In practice, however, the evaluation of each condition may take up several lines of code! Please keep this in mind when you formulate your answer. The essential point of the example is that the code block can be exited from anywhere in the block.


I am looking for a good way to achieve this similar effect in a bash script.

1 It is likely that this quick, from-memory description oversimplifies somewhat...
2 In fact, with this approach, one could also dispense with the overall_status variable altogether, and test $? instead.

EDIT: I added the "IMPORTANT: ..." clarification after the Perl example.

added 31 characters in body
Source Link
kjo
  • 16.4k
  • 25
  • 76
  • 125

One feature of Perl that it generalizesI really like is its generalization of looping control keywords to any curly-brace-delimited lexical block1. For

For example, one can use itsPerl's last directive to exit any such block, as the following toy script illustrates:

One feature of Perl that it generalizes looping control keywords to any curly-brace-delimited lexical block1. For example, one can use its last directive to exit any such block, as the following toy script illustrates:

One feature of Perl that I really like is its generalization of looping control keywords to any curly-brace-delimited lexical block1.

For example, one can use Perl's last directive to exit any such block, as the following toy script illustrates:

added 39 characters in body
Source Link
kjo
  • 16.4k
  • 25
  • 76
  • 125
Loading
Source Link
kjo
  • 16.4k
  • 25
  • 76
  • 125
Loading