Until now I had s/.pl// in a few places that was behaving very nicely and removing the .pl file extension from a group of strings. A week or more ago, I came upon it and mentally noted that I should correct it so the dot (.) was literal since the dot as currently written was for any character before pl. I didn't correct it. Well, a few nights ago, it finally bit me and made me make the correction. So now I have a well behaved regex, s/\.pl//. The word that caused this change was Temple. Instead of getting The Temple of Doom, I got The Tee of Doom. (Don't golf with that thing, please!) When I realized what was causing my little problem, I started giggling since I had told myself that not changing it would cause problems. Then today, it bit me again elsewhere. This time the word was People. The input was The Tomorrow People, however the output was humorous. I just started giggling at both results, today's is just a bit funnier.
If you want to see my output from today...
use strict; use warnings; my $title = "The Tomorrow People"; $title =~ s/.pl//g; print $title;
This is not the first time not thinking ahead when a less specific regex has caused me some trouble. I had /ssi/ for a match in a sort subroutine. Well, I did not take into account that those three letters could appear anywhere within a word. Sure enough, those letters appeared in Crossing Jordan making that title sort incorrectly. It took me a while to figure out that one. I finally traced it back to the source of the problem, and I now have /^ssi/ which is more accurate.
This was been a little lesson to me in thinking a little ahead when writing regexes. Have you had any humorous results from a regex?
|
|---|