I would:
Something like the following...
my %transactions; ... my @fields = split(/\s+/); my %rec; $rec{$_} = shift(@fields) for ( qw(date time tid status trname tramoun +t) ); if ( $rec{status} eq "start" ) { $transactions{$rec{tid}} = \%rec; } elsif ( $rec{status} eq "stop" ) { if ( exists($transactions{$rec{tid}}) ) { # report transaction time and amount } else { warn "ERROR: stop without start: $_"; } } else { warn "ERROR: unrecognized status: $_"; }
Update: and include the date in the transaction time calculation: think about what happens if the transaction starts late one day and stops early the following day.
In reply to Re: parsing and get the report
by ig
in thread parsing and get the report
by perlthirst
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |