I’m a beginner in Perl but have to develop some script to parse TCP-dump. Here it is (I truncated it and leave the relevant code only):
I get the following error: Thread 1 terminated abnormally: Invalid value for shared scalar at TestThread1.pl line 16, This is because of this string: %input = (%input, $fix_ClOrdID => [$FrameTime_epoch,$fix_MsgType]);
From many similar topics I’ve read I understand that I cannot share a nested references using threads::shared. And I also found some workaround how to do it. But due to lack of experience I can’t apply examples for my case.
Could you please advise how to fix my script to make it work!
use threads;
use threads::shared;
my %input:shared = ();
threads->new(\&FixParser)->detach();
sub FixParser{
open(InFile, 'myFix.dmp') || die;
while(InFile>){
($FrameTime_epoch,$fix_MsgType,$fix_ClOrdID) = split(';',);
if(exists($input{$fix_ClOrdID})){
$ExecDelay=$FrameTime_epoch-$input{$fix_ClOrdID}[0];
print "MsgType: $input{$fix_ClOrdID}[1] ExecDelay: $ExecDelay us\n";
delete($input{$fix_ClOrdID});
}
else{
%input = (%input, $fix_ClOrdID => [$FrameTime_epoch,$fix_MsgType]);
}
}
}
use strict; use warnings;, and the code as listed wouldn't compile. For example, I'm just eyeballing it but this linewhile(InFile>)should saywhile(<InFile>). Try addinguse strict; use warnings;and fix those errors. If there's still a problem you should ask again.