that doesn't work

Oh, but it does "work"; and has done since perl 4 days. Here's proof:

fred.pm:

#package fred; sub X123{ return 'x123'; } sub Y456 { return 'Y456'; } $localScalar = 'from fred'; @localArray = qw[ also from fred ]; %localHash = qw[ and this comes from fred as well ! ]; print 'fred.pm loaded';

And junk33.pl that does it:

#! perl -slw do './fred.pm' or die "$@ / $!"; print $localScalar; print @localArray; print %localHash; print X123(); print Y456();

And the output from a run:

C:\test>junk33 fred.pm loaded from fred alsofromfred well!comesfromandthisfredas x123 Y456

See subs and variables 'exported' into the calling code.

Of course, if you enable warnings, you do get a few:

C:\test>junk33 Name "main::localArray" used only once: possible typo at C:\test\junk3 +3.pl line 6. Name "main::localHash" used only once: possible typo at C:\test\junk33 +.pl line 7. Name "main::localScalar" used only once: possible typo at C:\test\junk +33.pl line 5. fred.pm loaded from fred alsofromfred well!comesfromandthisfredas x123 Y456

And if you enable strict, things start to fall apart:

C:\test>junk33 Global symbol "$localScalar" requires explicit package name at C:\test +\junk33.pl line 6. Global symbol "@localArray" requires explicit package name at C:\test\ +junk33.pl line 7. Global symbol "%localHash" requires explicit package name at C:\test\j +unk33.pl line 8. Execution of C:\test\junk33.pl aborted due to compilation errors.

And that is my point. do 'file' is "is almost forgotten, little used syntax," for a reason; Perl 5 vastly improved upon the mechanisms available in Perl4, by introducing packages & namespaces & lexical variables, and the tools (require & use) to make use of them.

And in order to achieve what you are asking for in the OP, is to return to Perl4 -- which Perl will allow you to do -- but to achieve it you need to throw away namespaces and packages and lexical variables and strict & warnings. If you're prepared to do that, perl makes it simple. If you are not; then you might reconsider the reasons why you want to do it.

I could have told you: thou shalt not; but it's better that you understand the reasons why it probably better that you don't; that you understand the trade offs; and what you have to give up in order to avoid re-structuring the code that you are so adamant that you cannot do.

In other words; what you are asking for is doable; but given the trade-offs, you'll probably decide that you don't actually want to do it any more. But it is your decision to make.


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 knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Exporting all variables and subroutines using Exporter by BrowserUk
in thread Exporting all variables and subroutines using Exporter by t-rex

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.