in reply to Execute function before exit of do() block

If you study the documentation of do, you can notice it behaves as eval. It means, you can check the problems in the calling script. If you want to check the problems in the called script, you can use eval:
eval { print "Hello\n"; croak "bad thing"; print "There\n"; 1 } and print "Good bye\n";
See also Try::Tiny.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Execute function before exit of do() block
by gri6507 (Deacon) on Jan 29, 2014 at 17:57 UTC
    My main script is generic and can "execute" many different types of helper scripts. Not all helper scripts need (or even can) act on the detected bad event. That is why the detection of the bad event needs to happen inside the helper script, rather than the main script. Your solution would not work in my case.
      Not all helper scripts need (or even can) act on the detected bad event. That is why the detection of the bad event needs to happen inside the helper script, rather than the main script.

      What would detection of the bad event (...) inside the helper script script give you, if that helper script cannot act on the detected bad event as you are saying? Error detection has to happen in the main script, checking the for $@ as you already do.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        Allow me to clarify. Let's say that my helper scripts fall into three categories:
        1. ones that have no need to clean up after themselves and thus have no need to detect bad events
        2. ones that need to perform CleanUpX() routine on completion, regardless of how that completion is initiated (i.e. normal exit or a croak)
        3. ones that need to perform CleanUpY() routine on completion, regardless of how that completion is initiated (i.e. normal exit or a croak)
        As you can see, doing a single activity on the main script side is not an option. Each script has to clean up on their own, if needed. The question is how can I force the specific clean up in case of an abnormal exit (i.e. croak) of each helper script?
      Your solution would not work in my case.
      I proposed two solutions. Which one do you mean?
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ