gaal, your solution is a very nice one and with some modifications will perfectly fit in my program. Thank you.
ysth, I wrote a sample code to show how my program works and then I realized you were right - labels work fine if you call them from different packages. In my situation the program fails because I call end_request from $SIG{__DIE__}.
This is the sample code:
#!/usr/bin/perl
package A;
$SIG{__DIE__} = sub {
end_request(@_);
};
sub end_request {
print @_;
next LOOP;
}
print "start\n";
$x = 0;
LOOP: while($x != 5) {
$x++;
#die "die\n" if $x == 3;
end_request("die\n") if $x == 3;
}
print "end\n";
If you use it like this it will work, but if you uncomment the #die "die\n" if $x == 3; line you will get a Label not found for "next LOOP" error.
Using perl 5.8.4.