Did you end your required file with a non-zero value? According to perldoc -f require:
The file must return true as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with "1;" unless you're sure it'll return true otherwise. But it's better just to put the "1;", in case you add more statements.
I whipped up a couple of files to test, and had no problem. try.pl looked like this:
use strict; use warnings; require 'try.req'; my $def = $::DEF{'two'}; mkDec($def);
and try.req looked like this:
print "I'm loaded\n"; %DEF = (one => 1, two => 2); sub mkDec{ print "MkDec received ($_[0]) OK\n"; } 1;
Output from running try.pl was
Name "main::DEF" used only once: possible typo at try.pl line 7 I'm loaded MkDec received (2) OK

Caution: Contents may have been coded under pressure.

In reply to Re: require and its subs by Roy Johnson
in thread require and its subs by Anonymous Monk

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.