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

Re: getting numeric data from a file into an array

by roboticus (Chancellor)
on Nov 01, 2011 at 17:43 UTC ( #935170=note: print w/ replies, xml ) Need Help??


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

jmccaslin:

Here's a quickie example:

use strict; use warnings; while (my $line = <DATA>) { chomp; print "INPUT LINE: $line\n"; # Read all the times from the line and place into array my @times = ($line=~m/[-+0-9.E]+/g); # Print the values print $_*1000, "\n" for @times; } __DATA__ 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

This gives me:

$ perl foo.pl Use of uninitialized value $_ in scalar chomp at foo.pl line 5, <DATA> + line 1. INPUT LINE: 2.83506E+03 2.83697E+03 2.83911E+03 2835060 2836970 2839110 Use of uninitialized value $_ in scalar chomp at foo.pl line 5, <DATA> + line 2. INPUT LINE: 2.84117E+03 2.84331E+03 2.84544E+03 2841170 2843310 2845440 Use of uninitialized value $_ in scalar chomp at foo.pl line 5, <DATA> + line 3. INPUT LINE: 2.84750E+03 2.84958E+03 2.85172E+03 2847500 2849580 2851720 Use of uninitialized value $_ in scalar chomp at foo.pl line 5, <DATA> + line 4. INPUT LINE: 2.85383E+03 2.85588E+03 2.85804E+03 2853830 2855880 2858040 Use of uninitialized value $_ in scalar chomp at foo.pl line 5, <DATA> + line 5. INPUT LINE: 2.86012E+03 2860120

...roboticus

When your only tool is a hammer, all problems look like your thumb.


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

    Thanks for the response, that seems to do what I need.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-07-29 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls