in reply to Re: Simple Question for you guys.
in thread converting carriage returns to <br> tags (was: Simple Question for you guys)

why have you escaped the < and > symbols? AFAIK they are not special inside a regex.

Replies are listed 'Best First'.
Re: Re: Re: Simple Question for you guys.
by blue_cowdawg (Monsignor) on May 18, 2001 at 17:41 UTC

    Simple. I felt like it. When in doubt escape. It doesn't cost much and it certainly doesn't hurt.

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Peter L. Berghold --- Peter@Berghold.Net
    "Those who fail to learn from history are condemned to repeat it."
    

      But there's no reason to be in doubt. Simply read the documentation - or try it out - and you'll know whether or not you need to escape characters.

      Escaping unnecessarily is a good way to confuse the next programmer to maintain your code.

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

        It is an intentional feature of Perl that a backslash followed by a non-word character always means the literal character, whether in a regex or a double-quoted string. Other languages and tools may use \( and \) for capturing parentheses, or \< and \> for word boundaries.

        Perl's rule is very simple. Personally, I don't see any harm in taking advantage of it. In fact, I think it is less likely to cause confusion, because another programmer can just look at the code and know immediately that \< means a literal <, without having to look at the docs or trying it out.

          Escaping unnecessarily is a good way to confuse the next programmer to maintain your code.

        As somebody who has done a lot of code maintenance on other folks code I would have to say that I never been confused by an escaped character.

        There are plenty of other sins out there that can cause confusion when maintaining code, believe me. If "unnecessary" escaping was the worst thing I ever saw I'd still have a full head of hair!

        
        ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        Peter L. Berghold --- Peter@Berghold.Net
        "Those who fail to learn from history are condemned to repeat it."