all of the module structure
If you only want to share a variable, the module structure isn't that heavy:
package MyModule; our $variable = "This variable is visible outside";
Now with use or require of MyModule, you can access $MyModule::variable. (our actually creates an alias so that $variable points to $MyModule::variable inside the MyModule.pm file).

Otherwise, if your file only contains the data, and no definition, for example:

# data.pl { Stuff => 1 }
You can use do like this: my $data = do "./data.pl"; (ie, the definition of the variable in the calling script, that way each script using the data can define its own name).

Edit: "./data.pl" is better than "data.pl" because do searches in the folders of @INC, which does not contain the current one by default in perl >= v5.26


In reply to Re: including variables by Eily
in thread including variables by LloydRice

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.