Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Regex and leading zeros in numbers

by flyingmoose (Priest)
on Mar 24, 2004 at 17:42 UTC ( [id://339488]=note: print w/replies, xml ) Need Help??


in reply to Regex and leading zeros in numbers

Regarding the (\d)(\d) repitition you are using, I highly recommend you pick up a copy of "Learning Perl" and "Programming Perl" -- the O'Reilly Camel and Lllama books, as these explain regexes, and the fact tht you can do things like (\d{0..9}) or (\d*) to specifiy a certain number of digits.

It always helps to read a little documentation before charging too deeply into new things! :)

While the 'don't use regexes' comments are 100% right, a regex cleanup solution could look something like $x=~s/[0]?(\d+)/$1/;. The question mark means 'optional', and the '+' means 'one or more of'. The $1 represents what you matched inside parens between the first set of slashes. So we are replacing digits with a leading zero with just the digits.

Again, read the docs, they are excellent. (as usual, all code is untested)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found