http://www.perlmonks.org?node_id=935276


in reply to getting numeric data from a file into an array

Here is a more "perlish" Warning-free way: (Deliberately avoiding regular expressions)
use strict; use warnings; my @values; my $special_string_found = 0; my $special_string = 'time values:'; while (defined( my $line= <DATA>)) { if (not $special_string_found ){ next unless $special_string eq substr($line,0,length($special_s +tring)); $special_string_found = 1; $line = substr($line,length($special_string)+1); } push @values, split(' ' ,$line); } print qq|$_\n| for @values; __DATA__ TIME number of steps: 13 time values: 2.83506E+03 2.83697E+03 2.83911E+03 2.84117E+03 2.84331E+03 2.84544E+03 2.84750E+03 2.84958E+03 2.85172E+03 2.85383E+03 2.85588E+03 2.85804E+03 2.86012E+03

            "XML is like violence: if it doesn't solve your problem, use more."

Replies are listed 'Best First'.
Re^2: getting numeric data from a file into an array
by jmccaslin (Initiate) on Nov 02, 2011 at 04:10 UTC

    I appreciate seeing the warning-free solution, and I must admit it's a little comforting to see it done without reg exp.