Hi Monks,

This is a bit of code I don't fully understand:
sub format_time{ my ( $h, $m, $s ) = @_; ... if ( length( $h ) < 2 ) { $h = "0" . $h; } if ( length( $m ) < 2 ) { $m = "0" . $m; } return $h . $m . $s2; } print format_time( 9, 5, 13 )."\n"; print format_time( 12, 34, 50 )."\n"; __OUTPUT__ 905 1235
I basically round the times and want to add a 0 in front of the minutes and hours if they have less than 2 chars anyway. This works fine for minutes but for some reason the 0 are "magically" replaced with a space character whenever used for an hour. I do not get the reason for this.

I am using AS Perl 5.8.4 Build 810.

Cheers for any help.

In reply to 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.