That is, the longer keys will appear first in the alternatives list and thus they will be matched first.$regex = join("|", map(quotemeta, sort { length $b <=> length $a } keys %hash)); s/($regex)/$hash{$1}/eg;
In reply to Re: Re: using a hash to do substitution?
by Masem
in thread using a hash to do substitution?
by mr.dunstan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |