Thursday, February 16, 2006

regex in Perl

While looking over code I created some time ago, I stumbled over a Perl-script to plot some vital data of a machine. I used Tobias Oetiker's excellent RRDtool to store the data and create the graphs.

BTW: The "Round Robin Database" is something you should definitely investigate if you need to store any kind of numerical value, graph the stored values, and especially if you don't want to make sure that only the current values are stored in the database. Believe you me!

The Perl-script contains a construct I'd like to share with you. The COMMENT modifier in RRDtool 1.2 and later does not like un-escaped ':' in the string to be printed. Here is the Perl code to do so:

$graphtime = localtime(time());
$graphtime =~ s/\:/\\\:/g;

That's regex in Perl, I really like it. Just don't forget to use Time::Local if you want to deploy this code.
;-)