home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!convex!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: How do I make traps in perl?
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Sep2.141332.14728@news.eng.convex.com>
- Date: Wed, 2 Sep 1992 14:13:32 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <1992Aug26.135146.1759@linda.lidac.liu.se> <1992Aug28.190101.9961@netlabs.com> <1992Sep2.122722.22017@unipalm.co.uk>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 40
-
- From the keyboard of ian@unipalm.co.uk (Ian Phillipps):
- :lwall@netlabs.com (Larry Wall) writes:
- :
- :> sub CATCHINT {
- :> print "OUCH! Don't DO that!!!\n";
- :> }
- :
- :I've wanted the equivalent of a longjmp to allow a sig handler to yank
- :me out of nest of routines etc, and plonk me down somewhere standard
- :(e.g. a main STDIN-reading loop). The "goto" spec is so discouraging
- :that I've not even tried it, and nothing else seems to fit.
-
- Have you not tried eval?
-
- 27) How can I do an atexit() or setjmp()/longjmp() in Perl?
-
- Perl's exception-handling mechanism is its eval operator. You
- can use eval as setjmp, and die as longjmp. Here's an example
- of Larry's for timed-out input, which in C is often implemented
- using setjmp and longjmp:
-
- $SIG{'ALRM'} = 'TIMEOUT';
- sub TIMEOUT { die "restart input\n"; }
-
- do {
- eval '&realcode';
- } while $@ =~ /^restart input/;
-
- sub realcode {
- alarm 15;
- $ans = <STDIN>;
- }
-
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
- > This made me wonder, suddenly: can telnet be written in perl?
- Of course it can be written in Perl. Now if you'd said nroff,
- that would be more challenging... --Larry Wall
-