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?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1212142 use strict; use warnings; my %cats = ( blackcat=>5, whitecat=>10,orangecat=>20 ); while(<DATA>) { print; s#([a-zA-Z][A-Za-z_0-9]+)# $cats{$1} // $1 #ge; print; } __DATA__ log10(blackcat)*whitecat*(log10(orangecat))

Outputs:

log10(blackcat)*whitecat*(log10(orangecat)) log10(5)*10*(log10(20))
  • Comment on Re: 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?
  • Select or Download Code