Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Why this is work?

by Jenda (Abbot)
on May 31, 2018 at 15:32 UTC ( [id://1215551]=note: print w/replies, xml ) Need Help??


in reply to Why this is work?

Actually ... not that you would be likely to get bitten by this, but just as a warning. Someone somewhere decided it'd be cool if \d matched "anything resembling a number in almost any of the writing systems ever used by humans" barely stopping short of matching the roman I, V, X, etc. On the other hand the automatic number conversion only understands 0, 1, 2, ... 9 so not all that matches \d+ may be converted to numbers. It was a bad idea, but I doubt it will ever be fixed.

If you want to be sure you only get what the rest of Perl considers numerals, use [0-9].

Jenda
Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^2: Why this is work?
by Your Mother (Archbishop) on May 31, 2018 at 16:10 UTC

    That's a bit narrow, no? Perl considers these numerals: 1_3 (or even 1____3 discounting strictures/warnings), 0xd, 0b1101, and 1.3e1 as you know. If \d should not match things Unicode defines as numbers then logically \w should not match any letters outside ASCII. /a and /u can be used to clarify and limit the regular expression too.

      say ('1_3' + 0); say ('0xd' + 0); say ('0b1101' + 0); say ('1.3e1' + 0);

      Literals are irrelevant, the conversion from string to number is what counts, because that's what's more often than not what happens to the matched string, and only the last one actually works.

      There's no reason whatsoever not to require \p{Number} for the rare use case of "give me anything that might be a digit to someone".

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1215551]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-26 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found