我繼承形式的功能:
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;
http://perldoc.perl.org/perlsub.html#Prototypes – Quentin 2014-10-22 10:40:14
HTTP:/ /stackoverflow.com/q/297034/1030675 – choroba 2014-10-22 11:50:55