eval has two purposes. If given an expression (EXPR),
eval
will evaluate that expression as a small Perl program. This is
generally the form of
eval that people term "evil," because it
delays execution of the code until runtime. And is thus slow.
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: $@";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.