Hi Monks,
I am trying to change the time that comes in as 19:45:34 as an example, to actually display like 7:45 PM. It Will have two variables to be checked, and I know what I am doing isn't efficient, since the code can just grow to long. There is anyone out there that could tell me a better way of doing that?
Here is the code:
my $xcltime = "19:45:34"; # It should print 7:45 PM my $xcltime2 = "23:35:14"; # It should print 11:35 PM if (($xcltime=~/(\d{1,2}):(\d{1,2}):(\d{1,2})/)||($xcltime2=~/(\d{1,2} +):(\d{1,2}):(\d{1,2})/)) { my $h1=$1;my $m2=$2; my $s3=$3; print "$h1,$m2,$s3<br>"; if($h1=~/13||14||15||16||17||18||19||20||21||22||23||24/) { $h1=~s/13/1/; $h1=~s/14/2/; $h1=~s/15/3/; $h1=~s/16/4/; $h1=~s/17/5/; $h1=~s/18/6/; $h1=~s/19/7/; $h1=~s/20/8/; $h1=~s/21/9/; $h1=~s/22/10/; $h1=~s/23/11/; $h1=~s/24/12/; $xcltime=$h1.":".$m2."&nbsp;PM"; $xcltime2=$h1.":".$m2."&nbsp;PM"; print "<b>$xcltime - $xcltime2</b><br>"; }else {$xcltime = $xcltime."AM"; print "<b>$xcltime - $xcltime2 +</b><br>";}

Thank you all very much!

In reply to Time transformation by Anonymous Monk

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.