in reply to printing column info without headers

Your while is going to read the whole file. Inside that loop, the if you currently have will operate on the headers. If you want to operate also on the lines that are not the headers, add an else to that.

while (<FILE>) { if (/^Number1/) { # header } else { # non-header } }

If you happen to have a data line that begins with 'Number1', however, it's going to treat that as a header. It might be better to read the file this way:

open ... my $header_line = <FILE>; while (<FILE>) { # data line }

Considering the format of your data, it might be easiest to use something like Text::CSV_XS.

Replies are listed 'Best First'.
Re^2: printing column info without headers
by annie06 (Acolyte) on Jul 09, 2008 at 15:28 UTC
    Not sure how your suggestion would work
    Maybe I wasn't clear in my question
    I'm basically asking how to search a large file where I know what the heading on the columns looks like, but then I want to actually grab the info in the columns.

      If the header line appears somewhere in the middle of the file, you could make use of a state variable (here $in_data_section). You'd initialize the variable to false, and set it to true as soon as you enconter the header line. And only when $in_data_section is true, you'd treat the input lines as data (numbers)...

      (Similarly, if you can tell what ends your data section, you could then reset the state variable to false...)

      ... my $in_data_section = 0; while (<FILE>){ chomp; if ($in_data_section) { my @numbers = split; #... } $in_data_section = 1 if m/^Number/; }

      Alternatively, if you know that there are exactly two data lines following the header, you could also do something like

      while (<FILE>){ chomp; if (/^Number/) { # found header, now we're expecting two lines with numbers for (1..2) { $_ = <FILE>; chomp; my @numbers = split; #... } } #... do other stuff }