Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
•Update: I've retracted this post, it doesn't apply to the situation (I missed the part about it being db records that need to be updated)
This stuff below is only useful if you need to do the substitutions in a string.
Produces the output: As you can see, it also handles circularity without problem; COM <-> SEC. Note that I'm sorting the keys on length to make sure longer patterns match first (otherwise "COM" would become "SECM"). If the search-string needs to occur as a word by itself, use \b, like: which prints:
Note that in this case sorting on the length of the key is not necessary, so you can simply do my $searchpat = join '|', keys %replace; Final note: this code assumes the keys don't contain any odd chars like regex metachars. Since your example shows all-uppercase abbreviations, so apparently this isn't a problem. If it is, then you'll need to look into using quotemeta. In reply to Re: Ordering hash replacements to avoid clobbering things
by xmath
|
|