eval – catch exceptions, execute string dynamically

You can use the eval function to catch exceptions in the case of block syntax. For string syntax, you can execute strings dynamically.

eval 

eval $string;

The one called eval string is the syntax to execute the string dynamically. Passing a string to eval will execute that string as a Perl executable statement. Errors that occur at runtime are stored in $@.

As an example, you can define a subroutine at runtime. The following example defines an eval string and a typeglob at runtime for a subroutine that return 5 foo: Temporarily allow symbolic references with no string refs.

#!/usr/bin/perl --

{
	no strict = 'refs';
	*{"foo"} = eval "sub {return 5}";
}
print "Content-type:text/html\n\n";
print $foo;

Internal Server Error

あれ?? 全然違う??