Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: the try/catch example from "Programming Perl" analyzed

by ambrus (Abbot)
on Aug 23, 2004 at 10:09 UTC ( [id://385038]=note: print w/replies, xml ) Need Help??


in reply to the try/catch example from "Programming Perl" analyzed

As trammell has noted, the prototype of try should be (&$), not (*&$), I guess that's only a typo but it has confused me very much when I've read it.

Also, that code is also listed in perldoc perlsub (of perl 5.8.2), I'm not sure which one copied from the other.

From perlsub:

The interesting thing about "&" is that you can generate new syntax with it, pro- vided it's in the initial position:

sub try (&@) { my($try,$catch) = @_; eval { &$try }; if ($@) { local $_ = $@; &$catch; } } sub catch (&) { $_[0] } try { die "phooey"; } catch { /phooey/ and print "unphooey\n"; };

That prints "unphooey". (Yes, there are still unresolved issues having to do with visibility of @_. I'm ignoring that question for the moment.

Replies are listed 'Best First'.
Re^2: the try/catch example from "Programming Perl" analyzed
by pemungkah (Priest) on Sep 09, 2004 at 17:53 UTC
    Thank you both; I've fixed that typo.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385038]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-28 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found