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

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.

Replies are listed 'Best First'.
Re^3: Want END block to run except when usage()/--help invocation
by Happy-the-monk (Canon) on Feb 27, 2015 at 07:44 UTC

    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
Re^3: Want END block to run except when usage()/--help invocation
by Laurent_R (Canon) on Feb 27, 2015 at 07:52 UTC
    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.
Re^3: Want END block to run except when usage()/--help invocation
by BrowserUk (Patriarch) on Feb 27, 2015 at 09:46 UTC

    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