다음과 같은 형식의 기능을 상속 받았습니다.
sub func($$) {
}
나는 다음을 보는 데 더 익숙합니다.
sub func {
## then extract params using shift for example
}
나는 조회 $$
했고 현재 프로세스 ID를 얻는 수단입니다. 하지만 함수를 살펴보면 여기에서 프로세스 ID가 사용 된 것처럼 보이지 않습니다. 그래서이 $$
맥락에서 다른 것을 의미합니까?
내가 의아해하는 기능은 아래의 parseMessage입니다. 왜 ($$)
?
use FileHandle;
# The structure of function is pretty much like this - names changed only
sub parseMessage($$)
{
my $string = shift;
my $fileHandle = shift;
my $Message = undef;
# parseAMessage and parseBMessage are functions to extract specific types of messages from file
if ( ($Message = parseAMessage($string, $fileHandle))
|| ($Message = parseBMessage($string, $fileHandle)) )
{
}
return $Message;
}
sub parseAMessage($$)
{
}
sub parseBMessage($$)
{
}
# The function seems to use arguments arg1: string from file, arg2: filehandle of file
# presumably idea behind this is to process current line in file but also have access to file
# handle to move to next line where required. So the way I am calling this is probably not
# great Perl - I am a beginner perler
$fh = FileHandle->new;
if ($fh->open("< myfile.log")) {
# here we evaluate the file handle in a scalar context to get next line
while($line = <$fh>) {
parseMessage($line, $fh);
#print <$fh>;
}
$fh->close;
}
print "DONE\n";
1;
그것들은 프로토 타입이며 함수가 인수로 취하는 것을 정의합니다 (안전하지 않습니다 ..).
그것은 당신이 당신이 호출하는 sub doSomething
것처럼 호출 할 수 있도록 내장 함수와 같은 함수를 정의 할 수 있습니다 print
.
doSomething($scalar)
나 doSomething $scalar
처럼 동일한 결과를 생성 할 print($scalar)
대print $scalar
위의 의견에 따라 : http://perldoc.perl.org/perlsub.html#Prototypes
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다