http://www.perlmonks.org?node_id=425608


in reply to Basic programming question

Perl has a special conditional operator (the ternary ?:) which is custom made for just this type of thing.
my $T = ($hour > 12) ? "PM" : "AM";
update: Whoops, just noticed that the OP is also decreasing $hour for the "PM" case. In that case, the ternary operator becomes a little more ugly.
my $T = ($hour > 12) ? do {$hour-=12; "PM"} : "AM";
Your best bet is probably one of the CPAN modules like dragonchild recommends.


-- All code is 100% tested and functional unless otherwise noted.