in reply to Want END block to run except when usage()/--help invocation

One way would be to set a flag in your usage() func and then bracket the code in the end block with: unless( $flag ) { ... }

Another would be to use POSIX::_exit() which will bypass END blocks (and other other cleanup including DESTROY funcs).


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: Want END block to run except when usage()/--help invocation
by CoVAX (Beadle) on Feb 27, 2015 at 07:31 UTC

    Thank you for this useful info.

    It also made me think of this question: Is there a way to dynamically disable 'use strict' and/or 'use warnings' at run-time?

    E.g. either entirely, or perhaps for a block:

    ... # disable 'use strict' and/or 'use warnings' do_some_code_known_to_cause_warnings(); # re-enable 'use strict' and/or 'use warnings' ...
    Searched for donut and crumpit. Found donate and stumbit instead.

      Is there a way to dynamically disable 'use strict' and/or 'use warnings' at run-time?

      Do not use the -w switch then, use warnings instead: # <- edited, see BrowserUK's correct comment below.

      use strict; use warnings; # ... no strict; no warnings 'uninitialized'; # only specific warnings switched off. # un-refined code use warnings 'uninitialized'; # escape to safety use strict;

      You don't need to switch off strict for the case in question, though.

      Cheers, Sören

      Créateur des bugs mobiles - let loose once, run everywhere.
      (hooked on the Perl Programming language)

        Do not use the -w switch then,

        No warnings work just as well with -w:

        C:\test>perl -wE"my $x; say $x; { no warnings 'uninitialized'; say $x +}" Use of uninitialized value $x in say at -e line 1.

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
      You can use the no strict or no warnings pragmas. It is usually better to disable only some of the strictures or of the warnings, for example:
      no strict 'vars'; no warnings 'recursion';
      and only for a limited scope.

      Update: fixed wrong formatting tags.

      Je suis Charlie.

      That's another way to go, provided that the code with the warnings doesn't do anything permanent, like write to a file.

      (But then, I wonder at the purpose of an END block that doesn't do anything permanent?)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked