develooper Front page | perl.beginners | Postings from March 2011

Re: transposing %d values to %x output

Thread Previous | Thread Next
From:
Jim Gibson
Date:
March 29, 2011 19:03
Subject:
Re: transposing %d values to %x output
Message ID:
p06240801c9b83da68168@[192.168.1.3]
At 9:18 PM -0400 3/29/11, Chas. Owens wrote:

>It is important to note that \d
>doesn't match what you think it does.  Starting with Perl 5.8, \d
>matches and digit character.  This includes characters such as
>"\x{1815}" (Mongolian digit five).  To match the ASCII digit
>characters you must use [0-9]:

I have heard this advice before, and it just sounds silly to me. I 
deal exclusively with ASCII characters, so \d will only match the 
characters '0' through '9'. If any UTF characters have crept into my 
data unknowingly, then I have a bigger problem than too many matches. 
If I am dealing with Monogolian characters or with any other set of 
UTC characters, then I certainly want \d to match them as well. There 
is a good reason why the set of characters matched by \d was expanded.

In other words, I see no reason to avoid using \d. Advising beginners 
to avoid the use of \d is just plain wrong. Can you provide any 
example of a situation where something bad will happen from using \d?

The statement "To match the ASCII digit characters you must use 
[0-9]" is wrong. I believe you meant to say "To match the ASCII digit 
characters and only those characters, you must use [0-9]".


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About