in reply to Re: Re: Regexes Are Not For String Comparison
in thread Regexes Are Not For String Comparison

I'm not disagreeing (I think), but I'm trying to get at why people reach for the more complex ones. Using m// isn't by itself complex and is usually one of the first Way Cool Perl features taught to newbies, and people can easily think that they understand the basic regex components (like $1 or /i or $^ or .*) that they've read about or seen used in tutorials. If you're saying that people use it just to make themselves look 'leet, I don't want to discount that, but it's more than just that -- there are reasons for thinking and choosing certain things, that has to do with the way the language is structured, or in how the language is learned.

-- Frag.

P.S. I'm confused on the problem with /(.*)/ -- do you mean /"(.*)"/? How can copying an entire string into $1 break? (Although it is certainly dumb.)

  • Comment on Re: Re: Re: Regexes Are Not For String Comparison

Replies are listed 'Best First'.
Re: Re: Re: Re: Regexes Are Not For String Comparison
by japhy (Canon) on Apr 24, 2001 at 21:29 UTC
    By asking how /(.*)/ can break, you're showing that you don't know that . can't match a newline, unless you use the /s modifier to a regex.

    And, they're doing things silly like

    if ($string =~ /.*/) { ... }
    or
    if ($string =~ /.*\.html/) { ... }
    Those show they don't know what they're doing. It's like seeing a hammer being used to pound a nail into wood, and then going around slamming a hammer into everything you see.

    japhy -- Perl and Regex Hacker

      Oop. Actually, I do know about that (and I use and know when to use /s, and /m) but I wasn't thinking of that when I read your comment. Which is still a screw-up, no excuses.

      -- Frag.