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.
In reply to Re: getting numeric data from a file into an array
by roboticus
in thread getting numeric data from a file into an array
by jmccaslin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |