tprayush has asked for the wisdom of the Perl Monks concerning the following question:

hi all.... plz tel me how can i solve this....here's the situation (this is just a sample!!)..
$ cat sigtrap #!/usr/bin/perl $SIG{'INT'} = 'ABORT'; sub ABORT { print "\nStop the loop?? (y/n) : "; chop($ch=<STDIN>); if ($ch =~ /[yY]/) { exit(1); } else { redo; } } $no=0; while (1) { print "$no\n"; sleep 2; $no++ }
$ ./sigtrap 0 1 2 3 ^C Stop the loop?? (y/n) : n Can't "redo" outside a loop block at ./sigtrap line 16, <STDIN> line 1 +.
but how can i solve this ..i.e. continuing in the loop!! plz help!! thanx.

Replies are listed 'Best First'.
Re: how to continue in the loop after traping signal
by zwon (Abbot) on May 02, 2010 at 22:41 UTC

    Replace redo with return.

    PS Also, pass code through perltidy before posting, and don't use "Plz help!!" phrase in your posts - it may actually have effect opposite to desired.

Re: how to continue in the loop after traping signal
by bart (Canon) on May 02, 2010 at 22:43 UTC
    Just drop the redo and let the handler sub simply return. Though I don't fully trust it, it seems to work for me.
Re: how to continue in the loop after traping signal
by samarzone (Pilgrim) on May 03, 2010 at 06:30 UTC

    What does that while loop stands for? What do you want to do with $no and sleep 2 ?