S
shree
Dear Perl Gurus,
I have a tab delimited log file that contains data of system
downtimes. It has 4 fields namely ID, type of downtime (whether
planned or unplanned), date and duration of downtime (in secs). I'm
asked to compute totals for each month of each type. See input data
file provided and mocked output file.
Data File (does not contain header line)
ID Type Date DowntimeSecs
1 Planned 01/19/2003 5000
2 Unplanned 01/27/2003 900
3 Unplanned 01/29/2003 300
4 Unplanned 02/12/2003 3690
5 Planned 02/27/2003 1800
...
...
80 Planned 07/12/2003 6000
81 Unplanned 07/15/2003 8400
Hence, the needed output file should be like
MonthYear Planned Unplanned TotalDownTime
Jan2003 5000 1200 6200
Feb2003 1800 3690 5490
...
...
I started with the following code
my %count;
while(<DATA>) {
chomp;
my ($id, $type, $date, $downtime_secs) = split (/\t/, $_);
$count{$type} += $downtime_secs;
}
while (my ($key, $val) = each %count) {
print "$key, $val \n";
}
which outputs
Unplanned, 82000
Planned, 90000
How can I modify the above, to give my customer what they wanted. Also
if anyone can educate me to how to extract more detailed info as shown
below, I would greatly appreciate it. Thank you
MonthYear Planned Unplanned Total NoPlanned NoUnplanned NoOfTotal
Jan2003 5000 1200 6200 1 2 3
Feb2003 1800 3690 5490 1 1 2
...
...
I have a tab delimited log file that contains data of system
downtimes. It has 4 fields namely ID, type of downtime (whether
planned or unplanned), date and duration of downtime (in secs). I'm
asked to compute totals for each month of each type. See input data
file provided and mocked output file.
Data File (does not contain header line)
ID Type Date DowntimeSecs
1 Planned 01/19/2003 5000
2 Unplanned 01/27/2003 900
3 Unplanned 01/29/2003 300
4 Unplanned 02/12/2003 3690
5 Planned 02/27/2003 1800
...
...
80 Planned 07/12/2003 6000
81 Unplanned 07/15/2003 8400
Hence, the needed output file should be like
MonthYear Planned Unplanned TotalDownTime
Jan2003 5000 1200 6200
Feb2003 1800 3690 5490
...
...
I started with the following code
my %count;
while(<DATA>) {
chomp;
my ($id, $type, $date, $downtime_secs) = split (/\t/, $_);
$count{$type} += $downtime_secs;
}
while (my ($key, $val) = each %count) {
print "$key, $val \n";
}
which outputs
Unplanned, 82000
Planned, 90000
How can I modify the above, to give my customer what they wanted. Also
if anyone can educate me to how to extract more detailed info as shown
below, I would greatly appreciate it. Thank you
MonthYear Planned Unplanned Total NoPlanned NoUnplanned NoOfTotal
Jan2003 5000 1200 6200 1 2 3
Feb2003 1800 3690 5490 1 1 2
...
...