我想從我的perl腳本(sample1.pl)調用另一個perl腳本(sample.pl)中有8個參數的子例程。 我收到此錯誤。 錯誤顯示爲如何調用另一個perl腳本中有8個參數的子例程
"sum of 8 numbers is 0Illegal character in prototype for main::callng_prgm : $a,$b,$c,$d,$e,$f,$g,$h at D:/workspace/sdff/sample.pl line 4.
Use of uninitialized value $b in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $a in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $c in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $d in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $e in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $f in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $g in addition (+) at D:/workspace/sdff/sample.pl line 6.
Use of uninitialized value $h in addition (+) at D:/workspace/sdff/sample.pl line 6.
"
可以請你建議我如何做到這一點
sample1.pl
require 'sample.pl';
use strict;
use warnings;
my $sa = main_prgm();
sub main_prgm {
eval(callng_prgm(10,12,15,14,16,12,12,12));
}
sample.pl
use strict;
use warnings;
our ($a,$b,$c,$d,$e,$f,$g,$h);
sub callng_prgm ($a, $b, $c, $d, $e, $f, $g, $h) {
my $z = ($a+$b+$c+$d+$e+$f+$g+$h);
print "sum of 8 numbers is $z";
}
1;
Perl中的原型不是必需的,並且不像其他語言那樣工作,所以除非你知道他們做了什麼,否則不要使用它們。 (原型是包含在子名稱後面的parens)。一個子聲明應該是這樣的:'sub NAME {CODE}'(沒有parens) – TLP
您嘗試使用在perl5中未實現的命名參數您可以通過另一種方式實現http://perldesignpatterns.com/?NamedArguments – teodozjan