CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
How to convert string to an expression in PERL

 



thangdd
New User

Oct 31, 2009, 2:23 AM

Post #1 of 2 (2016 views)
How to convert string to an expression in PERL Can't Post

Hi every body!

I have a quesion for my problem with using mysql and perl programming.

- data from mysql is logic expression. After query I get it's value on string format:

my $data = "$sex < 1 && $age >= 17 && $age <= 40 && ',1,2,3,' =~m/(,)$optid(,)/";

In this expression $sex,$age,$optid is variables

- How to make Perl understanding this function?
my $sex,$age,$optid;
if ($data) {
........
........
}

as

if ($sex < 1 && $age >= 17 && $age <= 40 && ',1,2,3,' =~m/(,)$optid(,)/) {
........
........
}

Please!!!!


thangdd
New User

Nov 1, 2009, 7:23 PM

Post #2 of 2 (1950 views)
Re: [thangdd] How to convert string to an expression in PERL [In reply to] Can't Post

I know a solution, but from other member: Axweildr Blush
http://forums.devshed.com/perl-programming-6/simple-regular-expression-q-648933.html#post2356815


Code
if (&check($data,$sex,$age,$optid)) { 
print "OK";
}
} else {
print "FALSE";
}

sub check{
my ($data,$sex,$age,$optid) = @_;
my $returnVl = 0;
(@atoms) = split(/&&/, $data);
$if_string = "if (";
for (@atoms) {
$if_string .= "($_) && ";
}
#remove the last two & and a space
$if_string = substr($if_string, 0, -3).") {\n";
$if_string .= " return 1;
} else {
return 0;
}
";
eval ($if_string);
}


Thank every body!


(This post was edited by thangdd on Nov 1, 2009, 7:24 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives