Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
Before running the code, you might expect a few things to happen:package Exception; sub TIESCALAR { bless {}, $_[0] } sub STORE { print "Setting the value of ", '$@', "\n" } sub FETCH { 42 } package main; tie $@, 'Exception' or die "Unable to do what you want\n"; my ($foo, $bar) = (0, 0); eval { $foo = 42 / $bar }; print "The value is : $@\n"; $@ = 'blah '; print "Now the value is : $@\n";
When the eval catches the illegal by 0 exception, $@ is set and yet the STORE code is not called.
When the subsequent print occurs, the value is not 42, but the actual exception and the FETCH code is not called.
When I set $@ to 'blah', it begins acting as you might expect running the STORE code.
In the last print statement it is still behaving normally (running the FETCH code).
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tying $@ - weird behavior
by !1 (Hermit) on Sep 27, 2004 at 23:38 UTC | |
|
Re: Tying $@ - weird behavior
by qumsieh (Scribe) on Sep 28, 2004 at 06:27 UTC | |
|
Re: Tying $@ - weird behavior
by Anonymous Monk on Sep 27, 2004 at 20:39 UTC | |
by Limbic~Region (Chancellor) on Sep 27, 2004 at 21:25 UTC |