So I have a regex in perl which goes like,
my $texttosub = "log10(blackcat)"; #the value of "blackcat" can be found in a hash called "%cats" while ( $texttosub =~ s|([a-zA-Z][A-Za-z_0-9]+)|$cats{$1}|i ){ + print ("\n", " The value of cat = ", eval ($texttosub) ); ..do something.. } sub log10{....}
My question is, How do I ignore "log10" and only match "blackcat" for substitution? So that I can evaluate that "$texttosub" line and print of the log10 value of that "blackcat". What I am looking for is, say blackcat=>5, whitecat=>10,orangecat=>20, then, $texttosub = "log10(blackcat)*whitecat*(log10(orangecat))" ===>must become log10(5)*10*(log10(20)). I tried this,
while ( $texttosub =~ s/(?!log10)|([a-zA-Z][A-Za-z_0-9]+)/$cats{$1}/i + ){ ..do something.. }
But I am getting an infinite loop for some reason. Thanks in advance.
In reply to Is there any way to ignore certain words and keep it as it is when substituing hash values to a matched pattern in a string? by skooma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |