[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-win32-users
Subject:    Re: please help with this parsing
From:       "$Bill Luebkert" <dbe () wgn ! net>
Date:       2000-12-29 6:12:21
[Download RAW message or body]

"Rivera, Claudia" wrote:
> 
>      You are right, the situation is a little bit complex, but here we go..
> 
>      I am receiving from a web page a math expression that includes arrays.
>     What I am doing is to take the math expression and convert it to perl
> code so that perl evaluates my expression.
> 
>         I already have done it without subscripts:
>         Example) I convert   "voltage+current" to "$data[$j][0] +
> $data[$j+1][1]", and perl evaluates it beautifully! :)
>      but I do not know how to do this substitution when I have subscripts
> since they contain different patterns (k,k+1,...).
>      Example:
>      Input:  voltage[k] + current[k+1]
>     Then I want to convert this expression to:   $data[$j][0] +
> $data[$j+1][1]
>     As you can see my information for each variable above is stored in a
> multimedimensional array starting at 0.
> 
> 
>     I also got to a point where I convert "voltage[k] + current[k+1]" to
> "voltage[$j] + current[$j+1]"
> 
> *****
>    I do not know if this is clear enough, but in conclusion all I want to
> know is how to find the pattern of any array of the following forms:
> array[k]
>                array[k+ "any number"]
>                array[k- "any number"]
> 
> and then substitute the name of the array for "data" and concatenate
> "[mynum]" to the end of the array
> 
> result:    data[k][mynum]
>               data[k+ "any number"][mynum]
>                data[k- "any number"][mynum]

Not the greatest help, but maybe something like this is what you want:

Convert 'array[k]'   to 'data[k][mynum]'
Convert 'array[k+n]' to 'data[k+n][mynum]' where n can be any decimal integer
Convert 'array[k-n]' to 'data[k-n][mynum]' where n can be any decimal integer

$_ = 'array[k] array[k+3] array[k-4]';

s/\w+\[(k([+-]\d+)?)\]/\$data[\$$1][mynum]/gi;

print "$_\n";

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--<  o // //      Mailto:dbe@wgn.net   http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic