codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Replacing patterns a^b with pow(a,b)  Almuc at 15:54 on Monday, August 20, 2007
 

Hi,

I need to format some experssions calculating power.

a^b to be replaced with pow(a,b)

This is the perl script that I wrote, but is does not work.
Could anyone help me in correcting the error?

#!/usr/bin/perl -w

$_ = "0.02+2*v6^2+3*v7^3;";

s/\b*(a-z0-9)+^(0-9)\b/pow($1,$2)/g;

print $_;

Expected result: 0.02+2*pow(v6,2)+3*pow(v7,3);


Error Displayed:
\b* matches null string many times in regex; marked by <-- HERE in m/\b* <-- HERE (a-z0-9)+^(0-9)\b/ at srch_rplc_pow.pl line 5.
0.02+2*v6^2+3*v7^3;




Regards,
Alm UC

  Re: Replacing patterns a^b with pow(a,b)  hermanningjaldsson at 00:07 on Saturday, August 25, 2007
 

i think you can skip the star after \b because \b represents work boundaries and logically there should never be many word boundaries in a row.

and also the ^ character may be better to type [\^]

im not sure if the \b at end should even be there at all.

I dont have a solution to the problem though.



  Re: Replacing patterns a^b with pow(a,b)  Almuc at 23:34 on Thursday, August 30, 2007
 

Hi,

Thanks for your reply.

I was able to figure out the perl script. For anyone who might be interested it is:

s/(\w+)\^(\d+)/pow($1,$2)/g;


some text ... a^b

converted to :

some text ... pow(a,b)

-AlmUC


  Re: Replacing patterns a^b with pow(a,b)  arash farhad at 12:09 on Friday, March 12, 2010
 

Nice post about with pow. I like your blog very much because it has very interesting articles of different topics like oracle certification dumps, brain dump and dumps for ccna and their tips and tricks. I am a very big googler and search on different topics. Between searching i found your nice blog. Thanks for your this great blog.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: help in perl script
•  orphan files (owner account deleted in linux but files exists)
•  Re: Text wrapping on C# webforms buttons
•  Re: Replacing patterns a^b with pow(a,b)
•  Re: Problem - Object doesn`t support this property or method
•  great sight
•  Re: JavaScript: Not working in Firefox 3.x
•  Re: Difference between two dates including From & To date
•  Re: How to highlight text WITHIN a JTable cell?


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010