Tôi đang đối mặt với lỗi biên dịch trong khi khai báo đối số kiểu mảng trong việc loại bỏ chương trình con perl. mã hoàn chỉnh của tôi là dưới đây:Làm cách nào để truyền các kiểu dữ liệu mảng và băm cho các đối số con trong perl?
use Data::Dumper;
use Win32;
use Win32::Service;
use strict;
use warnings;
my @Services = qw(NNMAction RpcEptMapper smstsmgr SNMPTRAP);
my $server = 'nnmi.hclt.corp.hcl.in';
ServiceStatus($server , @Services);
sub ServiceStatus ($serverName,@serverServices)
{ my %statcodeHash = ( '1' => 'stopped',
'2' => 'start pending',
'3' => 'stop pending',
'4' => 'running',
'5' => 'continue pending',
'6' => 'pause pending',
'7' => 'paused' );
foreach my $serv (@serverServices)
{ my %status;
my $ret = Win32::Service::GetStatus($serverName , $serv , \%status);
if ($ret)
{ print "success \t$statcodeHash{$status{CurrentState}} \t$serv\n";
}
else
{ print Win32::FormatMessage(Win32::GetLastError()), "\n";
}
}
}
LẬP LỖI
>perl -w perl_RemoteServiceStatus.pl
Prototype after '@' for main::ServiceStatus : $serverName,@serverServices at per
l_RemoteServiceStatus.pl line 21.
Illegal character in prototype for main::ServiceStatus : $serverName,@serverServ
ices at perl_RemoteServiceStatus.pl line 21.
main::ServiceStatus() called too early to check prototype at perl_RemoteServiceS
tatus.pl line 16.
Global symbol "@serverServices" requires explicit package name at perl_RemoteSer
viceStatus.pl line 31.
Global symbol "$serverName" requires explicit package name at perl_RemoteService
Status.pl line 33.
Execution of perl_RemoteServiceStatus.pl aborted due to compilation errors.
Vui lòng giúp tôi gỡ rối ths mã. Tôi chắc chắn nó sẽ là một miếng bánh cho một số người.
perl không có cơ chế khai báo các loại đối số. nguyên mẫu trông giống như họ làm điều đó ngay từ cái nhìn đầu tiên, nhưng trong thực tế phục vụ một mục đích hoàn toàn khác nhau; bạn không nên sử dụng chúng. – ysth