Dear Monks,

I have two simple modules:
package Demo1; use base qw/Exporter/; $SUCCESS = 1; BEGIN { use Exporter(); @ISA = qw(Exporter); @EXPORT = qw( $SUCCESS ) } 1;
and
package Demo2; sub import { ${[caller]->[0].'::'}{$_} = ${__PACKAGE__."::"}{$_} foreach grep { not /^(ISA|isa|BEGIN|import|Dumper)$/ } keys %{__PACKAGE__."::"}; } use constant { SUCCESS => 0, }; 1;
and a minimalistic test program, that is
#!/usr/bin/perl use strict; use warnings; use Demo1; use Demo2; print "SUCCESS: ", SUCCESS, "\n"; print "\$SUCCESS: $SUCCESS\n"; exit;
If I run the program as shown, I see an compile time error, like
Bareword "SUCCESS" not allowed while "strict subs" in use at ./demo.pl + line 9. Execution of ./demo.pl aborted due to compilation errors.
but if I simply change the order of the use instructions, i.e. I run
#!/usr/bin/perl use strict; use warnings; use Demo2; use Demo1; print "SUCCESS: ", SUCCESS, "\n"; print "\$SUCCESS: $SUCCESS\n"; exit;
then the displayed result is the expected one,
SUCCESS: 0 $SUCCESS: 1
I'd love to understand what's happening here - and would bve grateful to learn if there is a way to not have to use the two modules in a strict order in order to have the code working nevertheless.

Many thanks in advance.

In reply to How relevant is the order of 'use's ? by Krambambuli

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.