Re: Perl recipe for turning lines of numbers into an array?
- From: Octavian Râsnita <orasnita@xxxxxxxxx>
- To: <programmingblind@xxxxxxxxxxxxx>
- Date: Tue, 24 Feb 2009 22:32:58 +0200
I thought you will get those lines from a file, and that's why I gave that
example with <DATA>.
Glad it works.
Octavian
----- Original Message -----
From: "Sina Bahram" <sbahram@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, February 24, 2009 10:00 PM
Subject: RE: Perl recipe for turning lines of numbers into an array?
By the way, I jused used the functionality of open to open my string as a
stream, and your snippet worked like a charm.
Thanks much!
Take care,
Sina
-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Octavian Râsnita
Sent: Tuesday, February 24, 2009 2:17 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: 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
__________
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: