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

In reply to Re^2: Regex not matching as expected by stevieb
in thread Regex not matching as expected by Fisherman166

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.