#! /usr/bin/perl -wl # mytime3+ script # Tim Maher, tim@TeachMePerl.com, www.MinimalPerl.com # Improvement to mytime3, from p. 386 of Minimal Perl book. (undef, $minute, $hour)=localtime ; # leave seconds undefined #=====> Convert military time to "civilian" time = 12 and $am_pm='PM'; # hours 12-23 are afternoon $hour > 12 and $hour=$hour-12; # 13-23 ==> 1-11 (PM) $hour == 0 and $hour=12; # convert day's first hour $minute 2 or $cl_width=80; $string=shift; # get sub's argument $string=expand $string; # convert tabs to spaces $string =~ s/^\s+//; # remove leading whitespace $string =~ s/\s+$//; # remove trailing whitespace # calculate indentation $indent=($cl_width - length $string )/2; $padding=' ' x $indent; $newstring="$padding$string"; } return $newstring; # return centered string, or undef }