hi :)
sorry if the question sounds stupid, but i've read the die() doc, perlman::perlvar, and the oo tutorial, and haven't found nothing
sooo, what i'd like to do is to catch an interruption signal, and stop the program (doesn't look so hard ;]) - the point is that, as the program creates & calls some objects, it seems i have to wait for these objects to return before killing them (seems logical so far)
what i don't understand, is that those objects are created & used in a foreach loop, and my code seems to kill only the CURRENT object - then the loop goes on and creates the next object, while i'd like it to stop
maybe it's as simple as "your SIG{INT} isn't in the right place" or maybe is that i totally misunderstood perl's behaviour (hopefully not) ...
here is the code (part of)
my @list = split (....)
$SIG{INT} = \&catch_zap;
foreach my $nam (@list)
{
## Create foo object
my $foo = new SUB::foo;
$foo->name($nam);
...
my ($result, $error_message)=$foo->run;
...
## Save Data
my $file = ...;
open FH , "> $file" || die "Couldn't open file: $!";
...
print FH "$result \n";
close FH;
}
sub catch_zap
{
my $signame = shift;
&Warning("Somebody sent me a SIG$signame - trying to clean\n");
die "HEY I'M **done** STOP THIS PROGRAM __NOW__";
}
i let the file part in the foreach loop just to show there was something done after the call to "run"
so what happens is that the current object actually gets killed, i see the message from die, but the loop continues : the file is created, and then started again with a new object
if anyone knew where i fail, or how i could do to actually kill the program (exit the foreach loop, don't create the file, don't create nor call anymore object), i'd be really happy :))
thanx for having read ;]
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.