Although using this approach (split) is a logical one, I'd do anything to avoid the use of labels, and if I can do it in a single line of legible code, I'd prefer that over many. Also, you neglect to catch the 1. at the beginning, and then miss the $_ =~ in the latter part of your or.
I did a short benchmark on the two (split vs. my regex) after fixing the errors, just to see for myself for curiosity's sake, and the one liner regex is about twice as fast. (I didn't dig deeper to see where the hangups were, but I suspect they revolve in the numerous regex checks instead of one).
use warnings;
use strict;
use Benchmark;
open my $fh, '<', 'in.txt' or die $!;
timethese(1000000, {
regex => '_regex',
split => '_split',
});
sub _regex {
seek $fh, 0, 0;
while (<$fh>){
if (/^\d+\.\s+(?:N\/A\s+|\d+\s+){2}(\w+)/){
#print "$1\n";
}
}
}
sub _split {
seek $fh, 0, 0;
LINE: while (<$fh>){
my ($x, $one, $two, $test_name, @remaining) = split;
for ($one, $two){
next LINE unless $_ eq 'N/A' or $_ =~ /^\d+$/;
#print "$test_name\n";
}
}
}
__END__
Benchmark: timing 1000000 iterations of regex, split...
regex: 20 wallclock secs (17.97 usr + 3.04 sys = 21.01 CPU) @ 47
+596.38/s (n=1000000)
split: 39 wallclock secs (35.57 usr + 3.35 sys = 38.92 CPU) @ 25
+693.73/s (n=1000000)
Contents of in.txt:
1. N/A 17497118 basic_mem_test 17036us FAIL 1
2. 17497118 N/A basic_mem_test 17036us FAIL 1
3. 17497118 17497118 basic_mem_test 17036us FAIL 1
4. N/A N/A basic_mem_test 17036us FAIL 1
|