Deviloper wrote:
The last time I considered using eval is years ago.
I remember that I had read an article somewhere that doing eval could lead to dramatic performance issues.
I want to use eval{} to check my db-transactions. I looking for informations at
perldoc eval, but there is nothing mentioned about performance influences. (I
also looked at programming the perl dbi book, eval is only mentioned one
time.... and the http://www.perl.com/pub/a/1999/10/DBI.html and
http://www.saturn5.com/~jwb/dbi-examples.html)
There are some good notes on using eval in the DBI perldoc - an excerpt:
A major advantage of the "eval" approach is that the transaction will
be properly rolled back if any code (not just DBI calls) in the inner
application dies for any reason. The major advantage of using the
"$h->{RaiseError}" attribute is that all DBI calls will be checked
automatically. Both techniques are strongly recommended.
Otherwise there is little difference between the two - *provided* you do
error checking on every call you make to the database.
I would lean towards using eval, as any DBI failures will be propagated
upwards to your app, and if you don't deal with them your app will die -
this is generally more desirable than continuing on, blithely unaware
that your database transactions have failed!
In terms of performance, any hit that the use of eval has on your code
will be completely negligible compared to the delays involved in waiting
for any SQL database.
My own testing shows that eval, in block form, is very fast indeed.
Remember that eval is the standard exception handling idiom in perl. If
you are ever not sure about the speed of a construct, feel free to test
it - there are many ways to do it, including the excellent 'Benchmark'
module.
- Justin
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/