Array/File Read Question 
Author Message
 Array/File Read Question

I am fairly new to perl and cgi and I have a question about trying to
read in a file.  It is a test file that is comma delimited.  I read in
the entire file by simply using:

But this puts each line of the file in each array element.  Is there a
way to have each element in the array be filled with just each comma
delimited element??  For example here's the input file text:
02/02/02, 07:00:00 AM, 12.1, 6, 3.4, 36.2, 4.8, 321, 356
02/02/02, 08:00:00 AM, 9.1, 12, 3, 17.6, 3, 149, 129
02/02/02, 09:00:00 AM, 16.2, 27, 5.4, 44.5, 3.7, 398, 340
02/02/02, 10:00:00 AM, 9.2, 21, 3, 24.2, 5, 639, 401
How can put each seperate term on each line into it's own space in the
array?? Instead of the each entire line haveing it's own element inthe
array.  ANy help would be great.  Thanks,
--Ryan


Fri, 24 Sep 2004 22:35:18 GMT  
 Array/File Read Question
  You can use the split function to identify target fields


{

   # process the fields

Quote:
}

  Check out the perl documentation.

perldoc -f split

RWW


Quote:
> I am fairly new to perl and cgi and I have a question about trying to
> read in a file.  It is a test file that is comma delimited.  I read in
> the entire file by simply using:
> open (DATA, "$file.txt");

> But this puts each line of the file in each array element.  Is there a
> way to have each element in the array be filled with just each comma
> delimited element??  For example here's the input file text:
> 02/02/02, 07:00:00 AM, 12.1, 6, 3.4, 36.2, 4.8, 321, 356
> 02/02/02, 08:00:00 AM, 9.1, 12, 3, 17.6, 3, 149, 129
> 02/02/02, 09:00:00 AM, 16.2, 27, 5.4, 44.5, 3.7, 398, 340
> 02/02/02, 10:00:00 AM, 9.2, 21, 3, 24.2, 5, 639, 401
> How can put each seperate term on each line into it's own space in the
> array?? Instead of the each entire line haveing it's own element inthe
> array.  ANy help would be great.  Thanks,
> --Ryan



Sat, 25 Sep 2004 00:51:46 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. newbie question: How to read a dir and put contents into an array

2. reading files into arrays?

3. reading a file, creating an array

4. Reading text file lines into an array

5. reading a file into arrays

6. Problem Reading a File into Array

7. Reading X lines from a file at a time into an array

8. Reading Lines Out of a XML File into a String or Array

9. hash efficiency and key/value/array reading file

10. Why do beginners read files into an array?

11. Loop with Array or Loop and Read File?

12. Reading file segments into an array

 

 
Powered by phpBB® Forum Software