I like to jump after the while(1). How to do that? Checking a special variable and last is not ok because the while expression contains an blocking call so it would be too late if the expression is checked.
#!/usr/bin/perl
use strict;
use warnings;
use feature qw( say );
use sigtrap 'handler', \&hup_handler, 'HUP';
my $counter = 0;
sub hup_handler { say 'HUP!!!'; $counter = 0; return; }
say 'It starts here';
while ( 1 ) {
sleep( 1 ); # Blocking call is in reality within while expression.
say ++$counter;
}
say 'It ends here';
This should be possible by throwing an exception, a.k.a. die(), inside your signal handler.
So try doing something like this:
Of course any of the module providing a more normal looking try/catch syntax would work.