I ran through this with the debugger:

$perl -d main.pl Loading DB routines from perl5db.pl version 1.25 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(main.pl:4): require "somefile.pl"; DB<1> S newform* newform::func1 newform::someFile newform::someFile1 DB<2> S main* main::BEGIN DB<3>

So the functions you are requiring are getting included in the package.. because that's where you require them.

One thing that require does is "check for redundant loading, skipping already loaded files." So in this case, the required script is getting included in the package. The package is compiled first. The second time that require is called is at the main, however this is after the package has been compiled. So at that time, the require fails/does not include the package a second time.

So I changed the main code to scope the function call:

use strict; require "somefile.pl"; use newform; &newform::someFile(); &newform::func1();

and it works as expected.

Alternatively you could do this in your main:
sub BEGIN { require "somefile.pl"; }

Which would force the require before the newform package, however you would have to also change the call to someFile in the newform package:

&main::someFile();

which might not make sense.

Hazah! I'm Employed!


In reply to Re: require issue. by osunderdog
in thread require issue. by ant

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.