Regexes are for patterns -- =~ is the "pattern-match binding operator".

I have to mildly disagree. I agree that /^$bar$/ is a dumb regex, but often string literal regexes without either the ^ or the $ are a perfectly reasonable idea.

Now it may be the sort of scripts I've been writing recently, but I almost never find an occasion to use the "eq" operator. And it isn't just that I want case insensitive matches. It's most often whitespace or added junk characters. If I'm trying to match the string "foobar" I don't really care if it is actually "foobar ". Or if I'm looking for the string "no such file or directory" I don't care if I hit "no such file or directory at line 26 of foobar.pl". So I'll use /^no such file or directory/i without a second thought.

So I'm not really sure how strict you were being in your definition of patterns (personally, when I read the word "pattern" I think of masses of '\'ed characters), but I often find regexes a nice fit for matching plain old strings with a bit of leeway. I don't know if I'm interpreting you as being more draconian than you intended, but there is a place for regexes in certain types of string comparison.

But /^$bar$/ really is dumb. Although my personal favorite for stupid regexes is /.*$bar.*/

If you have any trouble sounding condescending, find a Unix user to show you how it's done.
- Scott Adams


In reply to Re: Regexes Are Not For String Comparison by DeusVult
in thread Regexes Are Not For String Comparison by japhy

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.