I have inherited functions of the form:
sub func($$) {
}
I am more used to seeing:
sub func {
## then extract params using shift for example
}
I looked up $$
and it is a means to get the current Process ID. But looking at the function it doesn't look like the Process ID is used here. so does $$
mean something else in this context?
The function I am puzzled about is parseMessage below. Why the ($$)
?
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;