Re: math formula substitution and evaluation

2006-07-16 Thread Daniel D Jones
On Sunday 16 July 2006 13:20, Charles K. Clarkson wrote: > Daniel D Jones wrote: > : Ah! Simple change: > >Subroutines should not normally operate on external data. What do you mean by "operate on?" I avoid altering external data, but I don't see the harm in reading external data. Too, thi

RE: math formula substitution and evaluation

2006-07-16 Thread Charles K. Clarkson
Daniel D Jones wrote: : Ah! Simple change: Subroutines should not normally operate on external data. Pass data into and out of each subroutine. As a matter of style, I avoidsqashingwordsinvariableandsuborutinenamesalltogether. I like to use an underscore for most names. run_tests( [EMAIL P

Re: math formula substitution and evaluation

2006-07-16 Thread Dr.Ruud
Daniel D Jones schreef: > Given something like the following: > > my @variables = [3, 7, 13, 4, 12]; > my @tests = ("2*a+b==c", "c-d+a==e"); > > I need to be able to evaluate the mathematical truth of the tests #!/usr/bin/perl # beware: this approach is wrong use warnings; use strict; my

Re: math formula substitution and evaluation

2006-07-16 Thread Daniel D Jones
On Sunday 16 July 2006 07:26, Paul Johnson wrote: > On Sun, Jul 16, 2006 at 05:48:10AM -0400, Daniel D Jones wrote: > > It certainly does help. I thought about substitution but couldn't > > come up with a syntax. This seems to be exactly what I was looking > > for, but I'm running into a problem.

Re: math formula substitution and evaluation

2006-07-16 Thread Paul Johnson
On Sun, Jul 16, 2006 at 05:48:10AM -0400, Daniel D Jones wrote: > It certainly does help. I thought about substitution but couldn't > come up with a syntax. This seems to be exactly what I was looking > for, but I'm running into a problem. Here's code which demonstrates > it: [ ... ] > As you

Re: math formula substitution and evaluation

2006-07-16 Thread Daniel D Jones
On Saturday 15 July 2006 21:13, Rob Dixon wrote: > Daniel D Jones wrote: > > Given something like the following: > > > > my @variables = [3, 7, 13, 4, 12]; > > You want round brackets here. You've created an array with just one > element, with a reference to an anonymous array as its value. Doh

Re: math formula substitution and evaluation

2006-07-16 Thread Rob Dixon
John W. Krahn wrote: > > Rob Dixon wrote: >> >>s/([a-z])/$variables[ord($1) - ord('a')]/ge; > > You don't need the /e option there. (Try it if you don't believe me.) Fascinating. Thanks John. And all because the expression's inside an array index. s/([a-z])/$variables[do{ my $n = ord(

Re: math formula substitution and evaluation

2006-07-15 Thread John W. Krahn
Rob Dixon wrote: > > You can do exactly that in Perl, and a lot more simply: > > my @variables = (3, 7, 13, 4, 12); > my @tests = ("2*a+b==c", "c-d+a==e"); > > foreach (@tests) { > s/([a-z])/$variables[ord($1) - ord('a')]/ge; You don't need the /e option there. (Try it if you don't b

Re: math formula substitution and evaluation

2006-07-15 Thread Aaron Priven
On Jul 15, 2006, at 5:15 PM, Daniel D Jones wrote: Given something like the following: my @variables = [3, 7, 13, 4, 12]; As an aside, you meant parentheses here, not brackets. (Brackets return a reference to an anonymous array containing the list, not the list itself.) my @tests = ("2

Re: math formula substitution and evaluation

2006-07-15 Thread Rob Dixon
Daniel D Jones wrote: > Given something like the following: > > my @variables = [3, 7, 13, 4, 12]; You want round brackets here. You've created an array with just one element, with a reference to an anonymous array as its value. > my @tests = ("2*a+b==c", "c-d+a==e"); > > I need to be able to

Re: math formula substitution and evaluation

2006-07-15 Thread Tom Phoenix
On 7/15/06, Daniel D Jones <[EMAIL PROTECTED]> wrote: my @variables = [3, 7, 13, 4, 12]; my @tests = ("2*a+b==c", "c-d+a==e"); I need to be able to evaluate the mathematical truth of the tests, May I suggest Parse::RecDescent? If you can make a grammar out of your algebra, you'll have an easy