- Jul 29, 2001
- 27,703
- 12
- 81
So I've got this astro assignment where I have to write a program to search for periodicities in a data set. I have a decent knowledge of c++ and java, but I want to do it in perl 
I'm getting the syntax pretty well so far but I have a question concerning how to extract data from a file and put it into an array(s). The data file format is:
0.111111 0.222222
0.333333 0.444444
etc. Basically two columns of numbers seperated by 3 spaces.
number1 space space space number2 \n
Okay, so I can open the file
open(FD, "< test.dat") or die("Couldn't open test.dat\n") ;
and I can create assign and do basic operations on arrays so far.
Here's what I want to do: Create 2 arrays of equal length and assign data from one column to one and from the other column to the second. I found a great howto perl site but all it says is:
So if I understand this correctly, if I just did this, my first array element would be the entire first line "0.111111 0.222222"
So how do I set the proper arguments so that each number gets read into a spot in the array?
TIA
I'm getting the syntax pretty well so far but I have a question concerning how to extract data from a file and put it into an array(s). The data file format is:
0.111111 0.222222
0.333333 0.444444
etc. Basically two columns of numbers seperated by 3 spaces.
number1 space space space number2 \n
Okay, so I can open the file
open(FD, "< test.dat") or die("Couldn't open test.dat\n") ;
and I can create assign and do basic operations on arrays so far.
Here's what I want to do: Create 2 arrays of equal length and assign data from one column to one and from the other column to the second. I found a great howto perl site but all it says is:
Now let's look at how Perl gets data in and out of files.
=======
@file_data = <FD> ;
=======
Perl reads the entire contents of the file into the @file_data array. Perl considers each line to be everything up to the next line separator. By default that's '\n', but you can change it if you need to by redefining Perl's special variable '$/'. One case where you'd do that is if you wanted Perl to read the entire file into a string rather than an array.
So if I understand this correctly, if I just did this, my first array element would be the entire first line "0.111111 0.222222"
So how do I set the proper arguments so that each number gets read into a spot in the array?
TIA
