in reply to Re^4: using system command in regex
in thread using system command in regex
Of course it is dead slow. You are opening, reading and closing each file for 10 * 60 = 600 times to get the sum for each second. You should read each file once and store the sums in a hash, keyed by the timestamp, like so:
my %SMPP_count; foreach my $file (@files) { open (FILE,"$file"); while(<FILE>) { next unless /\b(?:GSM|SMPP)\b/; # avoid uninteresting +lines chomp; my @ary = (split /\s|\|/, $_) [3,21,24]; my $time = (split ' ', $ary[0])[4]; # first element is +t timestamp, right? $SMPP_count{$time}++ if $ary[0] eq $stamp and $ary[1] + eq "Submit" and $ary[2] =~ /(GSM|SMPP)/; }; } # now iterate over the keys of the hash to make up your sums for my $time ( sort keys %SMPP_count) { my $sum = $SMPP_count{$time}; ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: using system command in regex
by ravi45722 (Pilgrim) on Oct 15, 2015 at 10:41 UTC | |
by marto (Cardinal) on Oct 15, 2015 at 10:47 UTC | |
by shmem (Chancellor) on Oct 15, 2015 at 12:24 UTC | |
by ravi45722 (Pilgrim) on Oct 16, 2015 at 03:59 UTC | |
by shmem (Chancellor) on Oct 16, 2015 at 07:27 UTC | |
by ravi45722 (Pilgrim) on Oct 16, 2015 at 09:50 UTC | |
by soonix (Chancellor) on Oct 15, 2015 at 14:48 UTC | |
by shmem (Chancellor) on Oct 15, 2015 at 15:33 UTC | |
by soonix (Chancellor) on Oct 15, 2015 at 19:28 UTC |