in reply to Any difference between use and require regarding honoring prototype defined for sub?
Yes, there is a difference, use use and not require
should be documented in perlsub
if you use require, you'll need to use a forward declaration
$ perl -le "sub f($$@@){warn qq{@_}} f(@ARGV,@ARGV,@ARGV); " 1 2 3 4 5 5 5 1 2 3 4 5 at -e line 1. ## simulate "require" $ perl -le " eval q{sub f($$@@){warn qq{@_}}}; f(@ARGV,@ARGV,@ARGV); " + 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 at (eval 1) line 1. ## forward/early/prototype declaration $ perl -le " sub f($$@@); eval q{sub f($$@@){warn qq{@_}}}; f(@ARGV,@A +RGV,@ARGV); " 1 2 3 4 5 5 5 1 2 3 4 5 at (eval 1) line 1.
$ echo foo() called too early to check prototype at file line 12 |spla +in foo() called too early to check prototype at file line 12 (#1) (W prototype) You've called a function that has a prototype before + the parser saw a definition or declaration for it, and Perl could not +check that the call conforms to the prototype. You need to either add a +n early prototype declaration for the subroutine in question, or mov +e the subroutine definition ahead of the call to get proper prototype checking. Alternatively, if you are certain that you're calling t +he function correctly, you may put an ampersand before the name to av +oid the warning. See perlsub.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Any difference between use and require regarding honoring prototype defined for sub? (prototype)
by stewart_lee (Novice) on Nov 19, 2012 at 19:56 UTC | |
by Athanasius (Archbishop) on Nov 20, 2012 at 04:50 UTC | |
|
Re^2: Any difference between use and require regarding honoring prototype defined for sub? (prototype)
by stewart_lee (Novice) on Nov 21, 2012 at 17:27 UTC |