in reply to regex s/// using hash
I used this feature to improve kyle's solution in Re^2: Finding a random position within a long string (Activeperl Build 822). The pattern then looked like
and proved to be a lot faster than having the conditional in the replacement part of s///.s/(?(?{rand() >= 0.1})(?!))./?/g
However, your pattern will be very slow due to backtracking. Most of the time the $dict{$1} lookup will fail and the regex engine will backtrack. Each word in the string (per /\w+/) will render
matches. For a short question on here on Perlmonks, with say 130 words and an average word length of 4, you'll get 1300 attempted matches against the string. As you see, it quickly gets quite heavy.length * (1 + length) / 2
lodin
|
|---|