I don't recall having actually discussed your "move use strict" idea before. For this code, would it look something like this?

package Fred; require Exporter; @ISA = qw( Exportor ); $VERSION = 1.01; %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); @EXPORT_OK = ( @{ $EXPORT_TAG{'all'} } ); my %METHODS = ( foo => 'bar', bo => 'baz', ); @EXPORT = (keys %METHOD); use strict; foreach my $method (keys %METHODS) { *$method = sub { return $METHODS{ $method }; }; } die "Use of ", __PACKAGE__, " (v$VERSION) not supported.\n" if ! prerequisites(); 1;
Note that the above code contains several mistakes but the only complaint you'll get from Perl will be a fatal error for one thing that isn't a mistake. (Hmm, I would have thought that having warnings enabled would have given you a warning about one of the real mistakes, but my testing shows otherwise.)

I guess your idea might make sense if you only ever mention each variable exactly once (the "standard" variables appear to be exempt from the "used only once" warning, so there is one more thing to worry about if you try this trick when you need any nonstandard package variables). But I still don't consider it a sound design as it is too easy to imagine future changes resulting in some of the variables actually being used within the package.

And if you use the variable as part of a standard initialization (above the use strict), then your typos are not caught. If you use the variable below the use strict, then you get a fatal compile-time error.

Note that I did suggest just removing the BEGIN block before I mentioned my personal preference, which I find makes things more robust in the face of several kinds of stupid mistakes. Not that I want to encourage such mistakes. It is just that the failure modes of those mistakes don't clearly point a finger at the mistake. Otherwise I think I'd stop that habit.

        - tye (but my friends call me "Tye")

In reply to (tye)Re2: Why doesn't @EXPORT = (keys %METHODS) work? by tye
in thread Why doesn't @EXPORT = (keys %METHODS) work? by rrwo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.