M
Matthew Braid
[Note: I accidentally posted this in comp.lang.perl.tk. This is a repost
in a more appropriate group.]
Hi all,
First off - where in the docs is the information on BEGIN/END/INIT/etc
blocks? I've just spent a rather frustrating 30 mins or so trying to
find them. No doubt its somewhere obvious that I've missed, but still....
Anyway.
Is there a standard way of disabling END block evaluation? The problem
I'm having is that I've discovered that a package I'm using does a
fork/exec. Normally this is ok, but if the exec fails it then does a
CORE::exit to make sure the child ends. This triggers any END blocks
that were defined in the parent when they really shouldn't be firing.
I know I can get around it with something like:
BEGIN {
my $processid = $$;
END {
if ($$ == $processid) {
# DO STUFF
}
}
}
but I didn't realise that a package I was using was failing a forked
exec, so it took me a lot of very annoying debugging to discover what
the problem was.
Is there a way to tell perl to only run END blocks that were defined in
the current process (ie forked children only run END blocks that have
been defined after the fork)? Or a way of temporarily disabling END blocks?
It just seems like a nasty gotcha that has a very consistant (but quite
ugly) workaround.
MB
in a more appropriate group.]
Hi all,
First off - where in the docs is the information on BEGIN/END/INIT/etc
blocks? I've just spent a rather frustrating 30 mins or so trying to
find them. No doubt its somewhere obvious that I've missed, but still....
Anyway.
Is there a standard way of disabling END block evaluation? The problem
I'm having is that I've discovered that a package I'm using does a
fork/exec. Normally this is ok, but if the exec fails it then does a
CORE::exit to make sure the child ends. This triggers any END blocks
that were defined in the parent when they really shouldn't be firing.
I know I can get around it with something like:
BEGIN {
my $processid = $$;
END {
if ($$ == $processid) {
# DO STUFF
}
}
}
but I didn't realise that a package I was using was failing a forked
exec, so it took me a lot of very annoying debugging to discover what
the problem was.
Is there a way to tell perl to only run END blocks that were defined in
the current process (ie forked children only run END blocks that have
been defined after the fork)? Or a way of temporarily disabling END blocks?
It just seems like a nasty gotcha that has a very consistant (but quite
ugly) workaround.
MB