Re: Simple regex question



Bryan <b@xxxxxxx> wrote:

Hi,

If I have this:
my $v1 = "9"; #Needs to be "09"
my $v2 = "01"; # Okay
my $v3 = "3"; # Needs to be "03"
my $v4 = "54"; #Okay

I want to make sure that all strings have the same format, which is 2
digits (or more) but that single digit values are padded with a '0'.
This is for a database query that happens later.

What is the regex to convert "1" to "01" and leaves "101" alone?

perldoc -f printf

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
.



Relevant Pages

  • Converting numbers to strings without Ada.Text_IO?
    ... I'm writing a collection of generic packages to format numbers (similar to ... determining the result strings' lengths in assignment. ... type Max_Real is digits System.Max_Digits; ...
    (comp.lang.ada)
  • Re: Formatting cells
    ... How should I format a cell to see 'aaa 1234 bbb' if a cell value is ... If you want to insert spaces between strings of letters and strings of digits, ...
    (microsoft.public.excel.misc)
  • RE: avoid scientific notation
    ... ONLY 2108 digits? ... elements of the resultant array to strings and append them together. ... > defaults to using scientific notation. ... Is there a way to tell VB to format to standard ...
    (microsoft.public.vb.general.discussion)
  • Re: Simple regex question
    ... Bryan wrote: ... I want to make sure that all strings have the same format, which is 2 digits but that single digit values are padded with a '0'. ...
    (comp.lang.perl.misc)
  • Re: Custom date format not working in ACC2003
    ... It forces the year to display as 4 digits in dates, ... setting the Format of the control won't rescue it. ... the date fields in reports always format ...
    (microsoft.public.access.reports)