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: Re: [thangdd] How to convert string to an expression in PERL: Edit Log



thangdd
New User

Nov 1, 2009, 7:23 PM


Views: 1904
Re: [thangdd] How to convert string to an expression in PERL

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)


Edit Log:
Post edited by thangdd (New User) 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