Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Small examples of string evalby ruzam (Curate) |
on May 14, 2006 at 03:16 UTC ( [id://549287]=note: print w/replies, xml ) | Need Help?? |
I have two places where I use eval all the time. I think eval is the best choice in these situations, maybe someone has a better alternative (that doesn't require non-core modules). 1) retrieving stored hashes I regularily used Data::Dumper to turn hashes into strings so they can be stored in a database for later retrieval. The string accurately represents the original hash with out my having to do a thing and it's safe to store anyway I have to, flat files, dbm, mysql. When the data is later retrieved, eval is the easiest way to get it back into a useful hash. Something like this:
1) wrapping DBI calls to capture errors. Far as I know this is the recommended (only?) way to do this. More generically I guess you could say eval is the tool of choice when ever you have to call code beyond your control that may kill your script.
In Section
Seekers of Perl Wisdom
|
|