Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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.

Comment on Re: the try/catch example from "Programming Perl" analyzed
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2015-10-09 08:07 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (236 votes), past polls