Maybe I misunderstand the question but, once you split your line into an array, you can test fields 6, 7 and 8 by doing something like this
use Scalar::Util (); # as advised by [choroba] my ($line, @arr); open my $fh, "<$ARGV[0]" or die "failed to open file $ARGV[0] for reading: $!\n"; my @check_fields = (6, 7, 8); my $line_counter = 0; LINE: while ($line = <$fh>) { $line_counter++; ### skip line if any of fields 6-8 are not numeric @arr = split /\s+/, $line; foreach my $i ( @check_fields ) { if ( ! Scalar::Util::looks_like_number($arr[$i - 1]) ) { # bad;this checks only for positive integers # (thanks Not_a_Number) # if ($arr[$i - 1] !~ /^\d+$/) { print STDERR "line num $line_counter: " . "1st problem field $arr[$i - 1]: " . "field num $i: " . "$line\n"; next LINE; } } ### the rest of your code }
This is just to show general approach. Code that does splitting and checking needs to be be extracted into a separate subroutine. With respect to "millions of lines" context of the question, not sure how efficient or inefficient this code is. Caching of test results could be useful, but then caching can take a lot of memory and backfire.

Update: took into account Not_a_Number's comment. Added comment on "millions of lines" issue.


In reply to Re: Find nonnumeric scalars by hotpelmen
in thread Find nonnumeric scalars by urbs33

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.