Assuming that libraries are being created, how does one take advantage of prototypes in the case where subroutines are spread across files? Given the following code:
#!/usr/bin/perl use strict; require 'include.pl'; sub localAdd($$); #sub remoteAdd($$); # Is this required? my $i; $i = localAdd 1, 2; #$i = localAdd 1, 2, 3; # error: "Too many arguments for main:local +Add at test.pl line 9, near "3;" print "i = $i\n"; #$i = remoteAdd 1, 2; # error: "Number found where operator expec +ted at test.pl line 15, near "remoteAdd 1" (Do you need to predeclare + remoteAdd?) #$i = remoteAdd 1, 2, 3; #print "i = $i\n"; $i = remoteAdd(1, 2); $i = remoteAdd(1, 2, 3); # prototype in include.pl is not honored print "i = $i\n"; sub localAdd($$) { my ($i, $j) = @_; return $i + $j; }
where include.pl contains the following:
sub remoteAdd($$); # This appears to have no effect across files... sub remoteAdd($$) { # die "incorrect #arguments in remoteAdd" unless @_ == 2; my ($i, $j) = @_; return $i + $j; } 1;
Prototypes get around expliciting checking for the number of parameters passed to a subroutine, but when subroutines are spread across multiple files, I no longer am seeing the interpreter perform this check for me. How do I get this functionality back for free?

Thanks for any insight on this issue.


In reply to subroutine prototypes effectiveness across files? 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.