in reply to Re: $@ alternative
in thread $@ alternative

I don't know :-(. And he did't answer. Can i add

{ local $@; ...my code goes here... }

to preserve $@?

Replies are listed 'Best First'.
Re^3: $@ alternative
by sgt (Deacon) on Sep 10, 2007 at 08:30 UTC

    $@ is global, so yes you can localize it, (and in general you should make a local copy if you want to preserve a previous exception).

    $@ being global, at the first exception triggered the previous contents of $@ will be destoyed, so that means probably your customer never used exception-eval blocks, or was just lucky, as the following code demonstrates.

    % steph@ape (/home/stephan/r) % % perl -we '$@ = "customer stuff..."; eval { die "dont muck with $@!" +}; print $@' dont muck with ! at -e line 1. % steph@ape (/home/stephan/r) % % perl -we '$@ = "customer stuff..."; { local $@; eval { die "dont muc +k with $@!" }; } print $@' customer stuff...
    cheers --stephan