nimdokk has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a program that takes in log files generated on both NT and Unix platforms. There are however a few discrepencies between the way the log files look on either platform. One is in how Timestamps are displayed. In this case, the Unix logs are quite readable and look nice when compared against the NT logs. I'm looking to add a routine of some sort into the script I have that parses the logs.

Here is how the data looks in the NT logs:

TransferStartTime=000042
TransferStartTime=HHMMSS
TransferStartDate=20030901
TransferStartDate=YYYYMMDD

I'd like to format that so that it ends up looking something like this:

Transfer Start Time= Mon Aug 4 01:45:13 2003

not necessarily exactly like that, but in a format that is easier for a person to read. I'm thinking about breaking the time/date fields apart and putting them back together into a more legible format. I'm not overly familiar with any extra modules that might help in this task so any suggestions would be most welcome.

Thanks in advance.


"Ex libris un peut de tout" update: retitled

Replies are listed 'Best First'.
Re: Advice
by dragonchild (Archbishop) on Oct 09, 2003 at 17:41 UTC
    Date::Calc will definitely be your friend in this endeavor. The Date modules in general are good to have under your belt.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Advice
by Zed_Lopez (Chaplain) on Oct 09, 2003 at 18:47 UTC
    See this perl.com article on date modules. What dragonchild said -- Date::Calc's your friend.
    use Date::Calc qw(:all); ($year,$month,$day) = ($transfer_start_date =~ /(\d{4})(\d\d)(\d\d)/); ($hour, $min, $sec) = ($transfer_start_time =~ /(\d{4})(\d\d)(\d\d)/); print sprintf "%.3s %.3s %d %02d:%02d:%02d %4d", Day_of_Week_to_Text(D +ay_of_Week($year, $month, $day)), Month_to_Text($month), $day, $hour, + $min, $sec, $year; # or, simpler and pretty close print join ' ', Date_to_Text($year, $month, $day), sprintf "%02d%02d%0 +2d", $hour, $min, $sec;
    (code untested)

      The only thing I noticed in your untested code was that the regex for $transfer_start_time should probably be /(\d\d)(\d\d)(\d\d)/ (given the HHMMSS format as per the OP).