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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|