60 likes | 223 Views
Dates and Times in Perl. CSCI333 – Systems Programming Friday, November 18, 2011. time. The time function returns the number of seconds elapsed since the system’s epoch (ex., January 1, 1970): $elapsed=time; Example: t1.txt. localtime.
E N D
Dates and Times in Perl CSCI333 – Systems Programming Friday, November 18, 2011
time • The time function returns the number of seconds elapsed since the system’s epoch (ex., January 1, 1970): $elapsed=time; Example: t1.txt
localtime • The localtime function returns a list of seven values: ($sec,$min,$hr,$mday,$mon,$yr,$wday,$yday,$isdst) =localtime(time); 0<=$sec<=59, 0<=$min<=59, 0<=$hr<=23, 1<=$mday<=31 0<=$mon<=11, $yr has 1900 subtracted from it 0<=$wday<=6, 1<=$yday<=366 $isdst=1 means Daylight Savings Time in effect Example: t2.txt
times • The times function returns a list of four values (user and system times for the current process and its children): ($user, $system, $cuser, $csystem)= times; Example: t3.txt
Time elapsed • To compute the time elapsed for a particular Perl code segment, you can use the times function: $beginning = (times)[0]; { do some stuff } $end = (times)[0]; $time_elapsed = $end - $beginning Example: t3.txt
Time::Piece module • The Time::Piece Perl module replaces the standard time functions in a backwards compatible manner. • http://search.cpan.org/~msergeant/Time-Piece/Piece.pm Example: t4.txt