DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 16th February 2009
qsecofr qsecofr is offline
Port Guard
 
Join Date: May 2008
Location: Portland
Posts: 18
Thanked 0 Times in 0 Posts
Default perl expression syntax

Hi,

Trying to solve a problem with either the eval or s///e functions, and I haven't succeeded yet.

I want to store an expression/equation in mysql. The expression contains the perl variable names. At runtime, I retrieve the record into a variable. And I evaluate the expression with the variables' current values.

something like
Code:
my $a;
my $b;
my $c;
my $result;
my $row;

# do stuff.  in the process setting $a = 5, $b = 6, $c = 2
...

# at this point assume $a = 5, $b = 6, $c = 2, expression: '($a * $b) / $c'
$statement->execute($parm);
$row = $statement->fetchrow_hashref();

$result = s//$row->{'expression'}/e;
# here i want perl to see there are variables in $row->{'expression'}, and
#  substitute the current values of those variables, and
#  calculate so that $result == 15.
Contrived example, of course. But I hope it's possible to do what I want. I've tried variations of dereferencing with $$variable, eval, and s///e. Haven't found the right syntax to calculate and return the result into a scalar variable.

Any perl expertise much appreciated!
TIA
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ Syntax highlighting in emacs rex FreeBSD General 1 12th October 2008 03:21 AM
PHP regular expression help cajunman4life Programming 2 16th August 2008 05:17 PM
Syntax Highlighting JMJ_coder Programming 17 22nd June 2008 02:24 PM
I need help with make.conf syntax troberts FreeBSD Ports and Packages 4 1st June 2008 03:58 AM
Vi type syntax applications corey_james Off-Topic 9 28th May 2008 04:15 PM


All times are GMT. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick