in reply to Seeking the
Based on your updated reply saying that you aren't planning on printing them, I can only assume you are using them for string comparisons. Otherwise, the presence of the leading zero would be meaningless in a numeric comparison. (And no, it wouldn't cause evaluation as octal.)
Also, like one other person showed, it would be much more efficient to get $month and increment it, rather than subscripting a constant array as you are in your sample code.
Getting back to your question, there are two ways to produce the strings you want:
($day, $month, $year) = (localtime)[3 .. 5]; $year += 1900; # Method 1: $day = sprintf "%02d", $day; $month = sprintf "%02d", $month + 1; # Method 2: $day = substr("0$day", -2); $month++; $month = substr("0$month", -2);
As you can see, printf is still you best tool here, though strictly-speaking you are using its cousin sprintf.
--rjray
|
|---|