Perl Home
PERL Functions
© 2011 TutorialsPoint.COM
|
PERL eval Function
Syntax
Definition and Usage
Evaluates EXPR at execution time as if EXPR were a separate Perl script. This allows
you to use a separate, perhaps user-supplied, piece of Perl script within your program.
An eval EXPR statement is evaluated separately each time the function is called.
The second form evaluates BLOCK when the rest of the script is parsed (before execution).
Return Value
Example
Following are the usage...
# make divide-by-zero nonfatal
eval { $answer = $a / $b; }; warn $@ if $@;
|
# __DIE__ hooks may modify error messages
{
local $SIG{'__DIE__'} =
sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
eval { die "foo lives here" };
print $@ if $@; # prints "bar lives here"
}
|
|

|
|
|