Re: converting text expressions (like "1+1") to values
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Sat, 29 Dec 2007 17:34:03 +0100
From: "Chas. Owens" <chas.owens@xxxxxxxxx>
On Dec 28, 2007 10:15 AM, Adarsh Srivastava
<Adarsh.Srivastava@xxxxxxxxxxxxxxxx> wrote:
Hello,snip
Is there any inbuilt/external function or library that can convert a text
expression (eg. "22 + 23") and evaluate the resulting value?( 45 in this
case).
Well, the string form of eval will do this; however, it is very
dangerous. What if the string contained valid Perl code* to do
something on your system? Any time you use the string form of eval
you should first run the string through a regex make sure it only
contains things you expect it to.
Another way to restrict what the evaled code may do is to use the
Safe.pm module.
use Safe;
$safe = new Safe;
$safe->reval("22+23");
HTH, Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- Follow-Ups:
- Re: converting text expressions (like "1+1") to values
- From: Chas. Owens
- Re: converting text expressions (like "1+1") to values
- References:
- Re: converting text expressions (like "1+1") to values
- From: Chas. Owens
- Re: converting text expressions (like "1+1") to values
- Prev by Date: Re: Handling errors when working with files
- Next by Date: Re: thumbs nails of file
- Previous by thread: Re: converting text expressions (like "1+1") to values
- Next by thread: Re: converting text expressions (like "1+1") to values
- Index(es):
Relevant Pages
|
|