- use strict; !!!!!
- Improved Regex checking
- Dates changed to arrays, to make comparison easier
- Cluttered, nested if's replaced by "next if" or "next unless"
- Test data you provided was used (no external files)
- Please remove the $today[1]-- : That was to compensate for old data
Cheers!
use strict; my @today = get_cur_time(); $today[1]--; # Compensate for old data ### Defining Jobs my @jobs = ("Allway Job"); ### Defining Print Header print "\n======================================\n"; print "\n Homebrew Reporting Program\n\n"; print " Today: @today\n"; print "\n======================================\n\n"; ### Opening Allway Sync Log File #open(FH1,"C:\\Documents and Settings\\localadmin\\Application Data\\S +ync App Settings\\_SYNCAPP\\default.log") # || die "Cannot open file:$!\n"; ### keep Log open while reading GETDATA:while(<DATA>){ #(<FH1>)) { 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 $_, "\t$syncStartD$syncStartT$syncStartjobName$filesProcesse +d\n"; }; }; ### Subroutines for current date 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__ [3/21/2008 12:48 PM] Synchronizing started, job: "Allway Job" [3/21/2008 12:48 PM] Analyzing finished, job: "Allway Job" [3/21/2008 12:48 PM] Deleting: "C:\test\_SYNCAPP\temp" ... [3/21/2008 12:48 PM] Deleting: "c:\test\_SYNCAPP\temp" ... [3/21/2008 12:48 PM] Preparing metadata ... [3/21/2008 12:48 PM] Flushing drive "\\.\C:" buffers ... [3/21/2008 12:48 PM] Writing File: C:\test\_SYNCAPP\metadata.xml" ... [3/21/2008 12:48 PM] Writing File: "c:\test\_SYNCAPP\metadata.xml" ... [3/21/2008 12:48 PM] Flushing drive "\\.\C:" buffers ... [3/21/2008 12:48 PM] Flushing drive "\\.\c:" buffers ... [3/21/2008 12:48 PM] Synchronizing finished, job: "Allway Job" [3/21/2008 12:48 PM] Summary: Files processed: 18; Files copied: 0; By +tes processed: 180,372; Bytes copied: 0.
"As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom
In reply to Re: Parsing Unstructured Data
by NetWallah
in thread Parsing Unstructured Data
by raj8
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |