in reply to help with a Perl term
Given a block (BLOCK), the block will be compiled at compile-time, rather than run-time (as in the EXPR form). If an error occurs in the expression/block that you're executing, the error message will be in the $@ variable after your eval.
In other words, eval, in combination with die, can be used as an exception mechanism in Perl. For example, you can try to require a module in an eval block, then check $@ (the "exception", in this case) to see if the require has succeeded:
eval { require LWP; }; if ($@) { die "Can't load LWP: $@"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: help with a Perl term
by Shendal (Hermit) on Jun 08, 2000 at 20:03 UTC | |
by KM (Priest) on Jun 08, 2000 at 20:19 UTC | |
by BBQ (Curate) on Jun 08, 2000 at 22:57 UTC | |
by Shendal (Hermit) on Jun 09, 2000 at 00:15 UTC | |
by BBQ (Curate) on Jun 09, 2000 at 00:23 UTC | |
by Shendal (Hermit) on Jun 09, 2000 at 00:28 UTC | |
|
RE: Re: help with a Perl term
by KM (Priest) on Jun 08, 2000 at 19:20 UTC | |
by btrott (Parson) on Jun 08, 2000 at 21:06 UTC | |
by KM (Priest) on Jun 08, 2000 at 21:16 UTC |