Hello to all! I have studied posts here for a while now, trying to improve my meagre Perl coding skills, but seemingly to little avail so far! I've been toying with alarms, in order to build a slideshow script. This thing will display random images, images in sequence forward or backwards or pause indefinitely on an image. If the user does not press a key within the timmeout period, the script repeats the last action. Sadly for reasons I don't understand, it works 99% of the time, and occasionally craps out with the following error message:
panic: leave_scope inconsistency at slideshow.pl line xx. panic: leave_scope inconsistency.
This corresponds to the "eval {" line in the code fragment below. Can anybody help explain what I've clearly failed to grasp?
do { $SIG{CHLD} = 'IGNORE'; undef $pid; die "fork: $!" unless defined ($pid = fork); if ($pid) { eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; do { # Wait for a keypress # Take appropriate action SWITCHKEY: { if ($key eq "q") { $continue = 0; last SWITCHKEY; }; if ($key eq "n") { $action = $key; $index++ ; last SWITCHKEY; }; if ($key eq "b") { $action = $key; $index-- ; last SWITCHKEY; }; if ($key eq ".") { alarm 0 ; last SWITCHKEY; }; $action = "r"; $index = int rand @files; } } until $key ne "."; alarm 0; # Close the current image window (by killing the child) kill TERM => $pid; }; if ($@) { # Timed out die unless $@ eq "alarm\n"; kill TERM => $pid; SWITCHACTION: { # n -> next image if ($action eq "n") { $index++; last SWITCHACTION; }; # b -> previous image if ($action eq "b") { $index--; last SWITCHACTION; }; # r -> random image if ($action eq "r") { $index = int rand @files; last SWITCHACTION; }; } } } else { # This is the child process # exec an image viewer over the child process... exec("/usr/bin/ee '$file'"); } } until not $continue;
Minds are like parachutes; they only work when open. (Sir James Dewar)

In reply to Why does my parent panic when comitting serial infanticide? by emptynet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.