I'm not understanding how your variables
$xcltime and
$xcltime2 are related. It looks like you're trying to set them both at once, to the same thing. Unless there's some weird dependency, you'd probably do best to extract out the time manipulation code into a subroutine, so the heart of your program can be just
$xcltime=convert_time($xcltime);
$xcltime2=convert_time($xcltime2);
or similar.
Then you just create a subroutine to do the conversion. I'd probably write it like this
sub convert_time{
my ($time)=shift;
my ($h, $m, $s) = $time =~ /^(\d\d?):(\d\d?):(\d\d?)$/;
my ($suffix);
if ($h > 12){
$h-=12;
$suffix=" PM";
} elsif ($h == 0) {
$h = 12;
$suffix=" AM";
} else {
$suffix=" AM";
}
return "$h:$m:$s$suffix";
}
Another issue is that your code inserts no space for AM, but an html nonbreaking space for PM. I've inserted the space in both cases, but you could change that if you really wanted to.
I've also included a fix for if the time is "00:15:17" or such, converting it to "12:15:17 AM".
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.