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") |