Chisel Wright [EMAIL PROTECTED] wrote:
> I've always been uncomfortable using eval().
> I know /how/ to use it, but it just feels dirty.
> What are the negative effects (if any) of using eval()?
Fundamentally here are two different ways of using eval (plus, of
course, the option of not using it all - which is preferable in *many*
situations):
1. eval "some string expression here"
This forces the perl interpreter to evaluate the string expression at
run time, each time it occurs, with the fairly obvious penalties for the
compilation phase prior to executing the code. You really, really,
really, want to avoid this construct if at all possible because of its
run time inefficiencies. You would use it whenever you have a perl
expression or code block that is created dynamically during the program
execution.
2. eval { some code block here }
The perl interpreter can evaluate and compile the block of code at
program startup time - exactly as it would for any other block of code.
This means that the eval doesn't present any significant overhead at run
time. Although you should try and avoid using eval when realistically
possible, this construct won't present dynamic compilation overhead, so
it's actually very efficient. You would use it whenever you have a perl
expression or code block that is known and constant.
For example,
my $template = HTML::Template->new (filename => 'thing.tmpl');
...
my $string = eval { $template->output };
if ($@) {
# eval failed...
}
Regards,
Chris
-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users