Hi Monks,
I have a string of numbers that comes into my program that supposable, it should have 6 digits long, like 123456, but sometimes it will come in to the program with 4 or 5 digits only, when that happens I have to add 0's to complement the string to have 6 digits.
Like if a string of number comes in with 1234, I have to add 0's to it like, 001234, so it can have 6 digits.
I have a regular expression that isn't working but my question is what is the best way to do this?
if($u=~/\d{4}?/){$u=~s/\d\d\d\d/00$u/;}
if($u=~/\d{5}?/){$u=~s/\d\d\d\d\d/0$u/;}
The code above isn't working because in both cases it match the digits it finds.
Thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.