Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
go ahead... be a heretic
 
PerlMonks  

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
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
Node Status?
node history
Node Type: note [id://385038]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-04-19 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls