I would make sure that you check that the date regex matched before using @date. Something like:next unless /Synchronizing started|Synchronizing finished|Summary/; my @date= m|(\d+)/(\d+)/(\d+)|;
The danger is that if the date regex fails, you will have no way of knowing about it. (Update: I guess this is not entirely true, but it is still good coding practice to always test if regex matches succeed or not.)my @date; if (@date = m{(\d+)/(\d+)/(\d+)}) { ... }
The next issue is: never mind... I didn't see how @today was defined
Here's what I think you want:
One key element of this loop is to save the last parsed job so we know which job a "Summary" line refers to. The list of jobs is keys %times.my %times; my $job; while (<FH1>) { next unless (s{^\[(\d+/\d+/\d+ \d+:\d+:\d+)\]\s*}{}); # malformed li +ne my $timestamp = $1; if (m/^(Synchonization|Analyzing) (started|finished), job: "(.*?)"/) + { $job = $3; $times{$job}->{$1}->{$2} = $timestamp; } elsif (m/^Summary:/) { $times{$job}->{summary} = $_; } } print Dumper(\%times); use Data::Dumper;
There are other ways of storing the timestamp data, and you may want to choose another data structure depending on how you plan to use the data later.
In reply to Re: Unique Data Formatting
by pc88mxer
in thread Unique Data Formatting
by raj8
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |