Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

For reasons of legacy code, our PERL interpreters have remained at 5.004 for quite sometime. We've now been forced to use PERL 5.8.8 and have run into some problems. Upon "compiling" our PERL scripts, we received a response that went something like "...forward-referenced functions were not prototyped...". Previously, our PERL script files have contained the main program first, followed by subroutines. Are we now being forced to use subroutine prototypes by version 5.8.8? I have searched perldoc.perl.org, Google, and perlmonks.org, but have not found anything that addresses this issue. Many thanks for your help.

Replies are listed 'Best First'.
Re: Forced to Use Subroutine Prototypes
by Joost (Canon) on Jul 24, 2007 at 18:04 UTC
    AFAIK you should not be forced to use prototypes anywhere where you didn't in 5.004.

    Two things that will help you find the cause of the problem:

    1. Search on the exact error message in google, for instance, and/or use the diagnostics module. Searching on google will have the advantage that it will probably also explain error messages that aren't caused by perl, since perl doesn't generate any warning/error like the one you've posted here.

    2. If that doesn't work, post the exact error message here and include (some of) the code that demonstrates the problem.

Re: Forced to Use Subroutine Prototypes
by Fletch (Bishop) on Jul 24, 2007 at 17:27 UTC

    When asking for help it's kind of important to provide the exact text of the error message (let alone a code sample which consistently reproduces the error message, but I digress . . .), otherwise it's going to be a crapshoot with people reduced to guessing as to what the actual error message really was.

    Looking in perldiag the closest I can find is the message when you've used a subroutine name without parens around its argument that hasn't yet been declared (either in the source in question or other code require'd or use'd lexically prior to the call in question). The quickest fix is to wrap the arguments in parens and be done with it; baring that use one of the perldiag suggestions and predeclare it (sub foo;) or move the actual declaration lexically before the invocation.

    As for prototypes, unless you're trying to mimic a perl builtin and/or really know what you're doing you don't want to mess with them.

Re: Forced to Use Subroutine Prototypes
by ikegami (Patriarch) on Jul 24, 2007 at 17:37 UTC

    Are you sure that's the error you got? I can't find any mention of it in perldiag.

    No, prototypes are not required. In fact, prototypes are not required on forward-declerations even if the sub has a prototype (although you run the risk of having the prototype silently ignored).

    use strict; use warnings; sub test1; sub test2; sub test3($$); test1; test2; # No prototype at this time. test3 'a', 'b'; # Args required by prototype. sub test1 { print "test1\n"; } sub test2($$) { print "test2\n"; } sub test3($$) { print "test3\n"; } test1; test2 'a', 'b'; # Args required by prototype. test3 'a', 'b'; # Args required by prototype.
Re: Forced to Use Subroutine Prototypes
by Anonymous Monk on Jul 24, 2007 at 18:34 UTC
    Thank you all! The code wasn't mine, but belonged to a colleague who happens to have a strong C background. Forcing the use of prototypes in PERL smacked of heresy. After you reassured me that prototypes weren't required, I was able to go to his code and point out where he had declared a PERL subroutine with a "C" accent like this: sub mySubName () { BLOCKOFCODE } Once the parentheses were removed in the declaration, PERL no longer complained that a prototype was needed. Grazie!
      Just to be clear, Perl wasn't complaining that a prototype was needed, it was complaining that you specified a prototype, but not early enough for it to be applied to a caller.