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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.