Assuming $hour is 0..23 initially,
my $T; for my $hour (0..23) { print "in: $hour "; if ($hour > 11) { $T = 'PM'; } else { $T = 'AM'; } ($hour %= 12) ||= 12; print "out: $hour $T\n"; } __END__ in: 0 out: 12 AM in: 1 out: 1 AM in: 2 out: 2 AM in: 3 out: 3 AM in: 4 out: 4 AM in: 5 out: 5 AM in: 6 out: 6 AM in: 7 out: 7 AM in: 8 out: 8 AM in: 9 out: 9 AM in: 10 out: 10 AM in: 11 out: 11 AM in: 12 out: 12 PM in: 13 out: 1 PM in: 14 out: 2 PM in: 15 out: 3 PM in: 16 out: 4 PM in: 17 out: 5 PM in: 18 out: 6 PM in: 19 out: 7 PM in: 20 out: 8 PM in: 21 out: 9 PM in: 22 out: 10 PM in: 23 out: 11 PM

In reply to Re: Basic programming question by ysth
in thread Basic programming question by j.goor

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.