http://qs321.pair.com?node_id=385038


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.