Thank you for your response. I'll do my best to add more detail (without being too detailed).
So at script startup-time, the parent immediately forks the child:
$socket = socketpair($child_fh, $parent_fh, .....);
$child_fh -> autoflush();
$parent_fh -> autoflush();
$pid = fork();
....
So the child and parent can use these file-handles to send and receive.
In the child process:
while(1)
{ my %INFO = ();
.... stuff-which-populates-%INFO ...
my $dumped = Dumper(\%INFO);
print $parent_fh ":MSG:${dumped}:DONE:\n";
sleep 10;
}
%INFO will always be populated ... it will never be null.
I am mindful that
$dumped could be upwards of 10Kbytes.
Hence, I frame
$dumped with
:MSG: and
:DONE:.
The parent process is a Perl/Tk GUI and so uses
fileevent() on
$child_fh to invoke a callback whenever there is activity on the file-handle.
So the call-back is of the form:
state $collected;
$num = read($child_fh, $buf, 1e6);
if ($num)
{ $collected .= $buf;
if ($collected =~ /:MSG:(.*):DONE:/s)
{ $dumper = $1;
%info = %{ eval $dumper }
$collected = "";
}
}
I make sure that the opening and closing framing text (
:MSG: and
:DONE:) is present, just in case the data is transacted in dribs-and-drabs.
As I write this, I guess it is possible that the asynchronous nature of data being collected in
$collected could be of the form:
:MSG:<Dumped-data-from-%INFO>:DONE::MSG:<Dumped-data-from-another-%INFO>:DONE:
And therefore the pattern match will match:
<Dumped-data-from-%INFO>:DONE::MSG:<Dumped-data-from-another-%INFO>
which is not in the correct format for the
eval.
At the time, I discounted this because of the
autoflush ... but perhaps that is a false assumption.
Following on from some of the tips provided, I have inserted:
local $SIG{__WARN__} = \&WhatsWrong;
and I have defined a function
WhatsWrong which can then print out the value of
$dumper.
It will take a few weeks for the problem to occur, so I will keep you updated when I have more information.
Thank you very much.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.