[nlug] Re: A Quick Perl Question

From: mike (Yeah, right)
Date: 05/11/06

  • Next message: Paul Boniol: "[nlug] Re: A Quick Perl Question"

    On 5/11/06, Michael Chaney <Yeah, right> wrote:
    > On Thu, May 11, 2006 at 03:04:58PM -0500, Tilghman Lesher wrote:
    > > On Thursday 11 May 2006 14:42, mike wrote:
    > > > eliminating spaces and allowing for existing dots or dashes:
    > > >
    > > > $phone =~ s/\s//g;
    > > > $phone =~ s/^([0-9]{3})[-.]?([0-9]{3})[-.]?([0-9]{4})$/$1-$2-$3/
    > >
    > > Slight problem: you need to backslash the hyphen in the second
    > > character class, or else it will translate to "all characters between
    > > NUL (\0) and period (0x2e)", which, while it includes the hyphen
    > > at 0x2d, also includes a lot more characters.

    this i did not know.

    > While you're at it, please use "\d" instead of "[0-9]".

    i had this discussion earlier with my coworkers. are there any
    reasons you know of why using \d is better than [0-9]? speed of
    compilation is mostly a non-issue, particularly for mod_perl
    applications that use pre-compiled regexes.

    i prefer [0-9] because it is more readable, easier to alter the range
    if neccessary, and reduces the number of backslashes in the regex that
    commonly lead to Leaning Toothpick Syndrome.

    also, from what i've read, \d and [0-9] are interchangeable,
    regardless of locale.

    -mike

    -- 
    Send all requests to:  Yeah, right
     Put your command in the SUBJECT of the message:
       "subscribe" or "unsubscribe"
    Quick unsubscribe: <mailto:Yeah, right?Subject=unsubscribe>
    Mailing list archives may be found at: <http://www.nlug.org/mail/>
    **********************************************************************
    This list is from your pals at NetCentral <http://www.netcentral.com/>
    

  • Next message: Paul Boniol: "[nlug] Re: A Quick Perl Question"

    This archive was generated by hypermail 2.1.6 : 05/11/06 CDT