I think you skipped an important bit of information. What error are you getting? The suggestions to prepend "&" will probably eliminate the error message, but may be like adding a typecast in C: it silences the complaint but doesn't fix the underlying problem. This solution should only be used when you fully understand the error message and have determined that the message is reporting a "false positive", that is, something that is often an error but isn't an error in this specific case. ar0n's answer sounds more likely to truely fix things.

The only reason I can think that you want to predeclare a sub in that context is that it has a prototype. Using & will just silence Perl and ignore the prototype. The correct fix is probably to make sure the declaration (or a predeclaration) of the function has been compiled before the call to that function is compiled.

As ar0n mentioned, require takes place at run time, so any function declarations in the required file won't be seen before the requiring script is compiled. Changing the "require" to "use" will cause the used file to be parse right after the "use" statement is compiled. It will also cause the "import" routine, if any, of the used module to be invoked right after that.

There are a lot of details possible here. But I think that most of them still lead to "use" being the correct way to fix it. Give us more details if you have doubts.

And predeclaration of functions look like this:

sub myfunc; sub mypackage::myfunc; sub mypackage::myfunc(); sub mypackage::myfunc(\%);
where the prototype (if any) should match the prototype (if any) used in the definition of the function.

        - tye (but my friends call me "Tye")

In reply to Re: Junior Monk Predeclaration Question by tye
in thread Junior Monk Predeclaration Question 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.