<?xml version="1.0" encoding="windows-1252"?>
<node id="1004600" title="Re: Any difference between use and require regarding honoring prototype defined for sub? (prototype)" created="2012-11-19 13:13:29" updated="2012-11-19 13:13:29">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;p&gt; Yes, there is a difference, use use and not require
&lt;p&gt; should be documented in perlsub
&lt;p&gt; if you use require, you'll need to use a forward declaration
&lt;c&gt;
$ 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,@ARGV,@ARGV); " 1 2 3 4 5
5 5 1 2 3 4 5 at (eval 1) line 1.
&lt;/c&gt;
&lt;spoiler&gt;
&lt;c&gt;$ echo foo() called too early to check prototype at file line 12 |splain
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 an
    early prototype declaration for the subroutine in question, or move the
    subroutine definition ahead of the call to get proper prototype
    checking.  Alternatively, if you are certain that you're calling the
    function correctly, you may put an ampersand before the name to avoid
    the warning.  See perlsub.
&lt;/c&gt;&lt;/spoiler&gt;</field>
<field name="root_node">
1004597</field>
<field name="parent_node">
1004597</field>
<field name="reputation">
13</field>
</data>
</node>
