where include.pl contains the following:#!/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; }
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?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;
Thanks for any insight on this issue.
In reply to subroutine prototypes effectiveness across files? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |