raj8 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I have come to a rock solid stop on this. I am attempting to gather data on files that I am syncing on my pc which I call jobs. For each job, I want to gather:
1.) Unique Date and Time for Analyzing
2.) Unique Date and Time for Sync to Start
3.) Unique Date and Time for Synchronizing Finished
4.) Unique Date and Time for Summary of each job.
As shown, the Summary line does not contain the job name. Therefore, I want to prefix the Summary data line with the job name. The problem I am having is that when I run the script it sometimes it prefixes an incorrect 'job' name on lines that do not belong to that particular job. I would hope that once I get this corrected, I could enter this data in a small mysql db for better reporting later. Anyway, thanks for your time and any suggestions that will help me overcome this battle.
use strict; my @today = get_cur_time(); ### Compensates for old data if needed ### #$today[1]--; ### Defining Jobs ### my @jobs = ("Job 3"); ### Defining Print Header ### print "\n======================================\n"; print "\n Today: @today\n"; print "\n======================================\n\n"; ### Opening Log File ### open(FH1,"c:\\default.log") || die "Cannot open file:$!\n"; ### keep Log open while reading ### GETDATA:while(<FH1>){ ### If not find..Carry on ### next unless /Synchronizing started|Synchronizing finished|Summary/; my @date= m|(\d+)/(\d+)/(\d+)|; for my $i(0..$#today) { next GETDATA if $date[$i]!=$today[$i]; } foreach my $job (@jobs) { my $syncStartD = substr($_,1,9); my $syncStartT = substr($_,11,7); my $syncStartjobName = substr($_,20,120); my $filesProcessed = substr($_,21,44); print $_, "\n$job: "; }; }; ### Subroutines ### sub get_cur_time { my ($Day, $Month, $Year) = (localtime(time))[3..6]; $Year += 1900; #--Note - the "sprintf"s are no longer necessary ... $Month = sprintf '%02d', $Month + 1; $Day = sprintf '%02d', $Day; return ($Month,$Day,$Year); }; __DATA__ [4/14/2008 4:44 PM] Analyzing started, job: "New Job 1" [4/14/2008 4:45 PM] Synchronizing started, job: "New Job 1" [4/14/2008 4:45 PM] Analyzing finished, job: "New Job 1" [4/14/2008 4:45 PM] Synchronizing finished, job: "New Job 1" [4/14/2008 4:45 PM] Summary: Files processed: 6,554; Files copied: 1; +Bytes processed: 1,633,599,552; Bytes copied: 1,221,120. [4/14/2008 5:03 PM] Analyzing started, job: "New Job 2" [4/14/2008 5:06 PM] Analyzing finished, job: "New Job 2" [4/14/2008 5:06 PM] Synchronizing finished, job: "New Job 2" [4/14/2008 5:06 PM] Summary: Files processed: 136; Files copied: 58; B +ytes processed: 14,427,075; Bytes copied: 14,427,075. [4/14/2008 5:08 PM] Analyzing started, job: "New Job 3" [4/14/2008 5:08 PM] Analyzing finished, job: "New Job 3" [4/14/2008 5:08 PM] Synchronizing started, job: "New Job 3" [4/14/2008 5:08 PM] Synchronizing finished, job: "New Job 3" [4/14/2008 5:08 PM] Summary: Files processed: 38; Files copied: 17; By +tes processed: 292,097; Bytes copied: 294,793.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unique Data Formatting
by pc88mxer (Vicar) on Apr 18, 2008 at 06:37 UTC | |
|
Re: Unique Data Formatting
by wfsp (Abbot) on Apr 18, 2008 at 06:42 UTC | |
by raj8 (Sexton) on Apr 18, 2008 at 16:43 UTC | |
by raj8 (Sexton) on Apr 18, 2008 at 18:52 UTC | |
by wfsp (Abbot) on Apr 19, 2008 at 06:08 UTC |