Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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

by ambrus (Abbot)
on Aug 23, 2004 at 10:09 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://385038]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-01-16 18:21 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (187 votes). Check out past polls.