Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: getting numeric data from a file into an array

by NetWallah (Abbot)
on Nov 02, 2011 at 03:05 UTC ( #935276=note: print w/ replies, xml ) Need Help??


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."


Comment on Re: getting numeric data from a file into an array
Download Code
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-09-19 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls