checking that numbers are in required format before using them

I have a script that does some string concatenation that includes numbers that get pulled from various places. Before I can use them, however, I need all the numbers to be in a consistent  format (usually, ###) so that they sort properly.

How do you write an IF statement that checks adds leading zeros as needed so that 1,10,100 become 001,010,100?

Thanks in advance.

Who is Participating?
Hi Leprechaun,

I would use a sprintf ... e.g.

$x = sprintf "%03d", $y;

In fact, you probably could use the sprintf to do all of your concatentation.

LeprechaunAuthor Commented:
Great, thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.