[Dub-pm] Time::Piece && while loops
Lee Hosty
hostyle at csn.ul.ie
Wed May 5 16:59:29 CDT 2004
Andrew Barnes wrote:
>
> What I want this script to do is keep writing out the connection info into
> this same file *until* the day changes - ala "automated log rotation" ;>
>
> SOooo... when talking to Doc on IRC last night we discussed using a while
is there Dub.pm IRC channel?
> loop to do this. My catch is trying to work out the "best way"
> (programatically, as well as "resource-wise") to do this - ie. check the
> day, and while $date != $date + 1, write into the log file - otherwise,
> update $date, $logfile, and write into the new file
I'm presuming you already have some sort of loop going for your log data
(and this is obviously rather simplistic):
my ($date, $time) = &get_date_and_time_as_array;
open (LOG, ">>$date.$time.txt");
while ($data) {
my ($newdate, $newtime) = &get_date_and_time_as_array;
# get log data
if ($newdate > $date) { close LOG; open (LOG, ">>$date.$time.txt"); }
print LOG $data;
}
close LOG;
How expensive is calling get_date_and_time_as_array / getting current
date? Depends on the amount / speed of data being logged.
--
Please excuse glaring errors; /me contains beer
More information about the Dublin-pm
mailing list