Perl Programming/Keywords/eval

Previous: eq Keywords Next: exec

The eval keyword edit

There are two uses of this keyword. The first form is the so-called "string eval" and executes the EXPRESSION as it were a Perl program. The second form, the code within the BLOCK is parsed once together with the code surrounding the eval itself, and executed within the current Perl program context. This form is typically used to trap exceptions more efficiently than the first, and also checking the code within BLOCK during compile time.

Syntax edit

  eval EXPRESSION
  eval BLOCK

Examples edit

  # This code warns on a divide-by-zero
  eval { $division = $divident/$divisor; }; warn $@ if $@;
  []
  eval { die "I lived here" };
Previous: eq Keywords Next: exec