Perl time manipulation

Friday, April 16, 2010 |



Its always a challenge for any system guy to maintain application/system performance metrics for analysis and capacity planning. Harvesting the data and plotting requires lot of time related calculations. Since I am a part time programmer, cannot blabber more on perl or python's data extraction/manipulation capabilities.
Today I came across couple of modules which made my life easy while manipulating time related data using a Perl script.

i.   Date::Manip

This is a smart module which can be helpful in converting the time and date.  RPM package of this module is available from RedHat, CentOS repos.

[bbaby@basilvm ~]$ rpm -qa | grep -i manip
perl-DateManip-5.44-1.2.1
[bbaby@basilvm ~]$


Example :
 ## Get current time 
$current_time = localtime;   

 ## Take the difference between time value passed and current time
 $time_diff = DateCalc($time_value, $current_time);
##  Time difference in minutes (%s for seconds)
 $time_min = Delta_Format($time_diff, 0,'%mh');    

 Big chunk of Date::Manip examples are available here

ii.  Time::HiRes
 High resolution alarm, sleep, gettimeofday, interval timers (Examples available here )

0 comments:

Post a Comment