in reply to front-pad a number with zero's

That's broken, due to the use of the string comparison operators (like lt) in the place of numerical comparison operators (like <). Also, a while loop can be replaced with math:
$string = ('0' x ($wanted - $current)) . $string;
But honestly, this is a job for sprintf():
sprintf "%0${len}d", $number;
That is, sprintf("%05d", 123) returns 00123.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re^2: front-pad a number with zero's
by Anonymous Monk on Jun 13, 2008 at 08:40 UTC
    You are a genius! Where did you get this sprintf "%0${len}d", $number; It's saved me a lot of troubles. 06-13-2008 Thank you.
      Where did you get this sprintf "%0${len}d", $number;
      The sprintf documentation, perhaps?
      printf '<%06s>', 12; # prints "<000012>"
      BTW: The thread you responded to is 7 years old.
      --
      No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
        I'm replying to a ten year old thread!