If I run the code you posted verbatim, except for removing the ..., I get 0905 in the first line. The problem in your code is elsewhere, either in that ... which you're hiding, or in another part completely.

Why would you think a zero character magically turns into a space? Are you sure a zero character was ever added? Try instrumenting your code:

sub format_time{ my ( $h, $m, $s ) = @_; ... warn "\$h is now '$h', length " . length $h; if ( length( $h ) < 2 ) { warn "going to pad with zero"; $h = "0" . $h; } if ( length( $m ) < 2 ) { $m = "0" . $m; } return $h . $m . $s2; }

I am almost certain you will find that the space is already there by the time you get to that conditional and that the second message from inside that code block never gets printed.

Always question your assumptions, and know what your code is doing, instead of programming by coincidence.

And then, when you've found the problem and taken away its lesson, throw away your code and use sprintf.

Makeshifts last the longest.


In reply to Re: scalar number with preceding 0. by Aristotle
in thread scalar number with preceding 0. by PerlingTheUK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.