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?

Have a cookie and a very nice day!
Lady Aleena

In reply to Writing regexes, think ahead just a bit. by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.