Re: Perl recipe for turning lines of numbers into an array?

This code does what you need:

my @array;

push(@array, [split(" ", $_)]) while <DATA>;

#Print the array to see if it is ok
use Data::Dump ('pp'); print pp(\@array);

__DATA__
298.25 1.2 -4
-194 1.239 -0.051
1.2 -253.221 100.24

Octavian

----- Original Message ----- From: "Sina Bahram" <sbahram@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, February 24, 2009 8:35 PM
Subject: Perl recipe for turning lines of numbers into an array?


Hi all,

I've got the following data, which I know will always be 14 rows long and 14 columns wide. The data is floating point numbers, the columns are separated
by spaces, and the rows are separated by new lines ... Here's a 3 by 3
example of the 14 by 14 data.

298.25 1.2 -4
-194 1.239 -0.051
1.2 -253.221 100.24

How can I turn that into an array with indicies 0 through 2 which each have
0 through 2 cells?

In other words a two dimensional 3x3 array with 9 elements?

Keep in mind numbers can be positive, negative,  and can have decimals.

If we have this in $matrix, how can we turn it into an array?

Thanks

Take care,
Sina

__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

Other related posts: