PDA

View Full Version : reading lines from a file into arrays


lmbylsma
11-11-2003, 11:57 PM
So basically what I'm trying to do is read data from a file and organize it into a table that I can later open in Excel. I wrote some code that I thought would work but its just not doing anything and I'm not getting any error messages so I have no idea what's wrong.

Here's a shortened version of what the data file looks like:

"INFORMATION"
"b2jun0302"
""
""
""
""
""

"SUMMARY"
"13" "Evt-" "correct" 1
"14" "Evt-" "incorrect" 1
"19" "Evt-" "rcor" 1
"20" "Evt-" "rincor" 1
"32" "Marker" "untitled"

"CHANNEL" "13"
"Evt-"
"No comment"
"correct"

49.89185
53.72692
57.82880
61.91400



"CHANNEL" "14"
"Evt-"
"No comment"
"incorrect"

214.23345
238.11100
287.04997
379.90897


So what I want for the output would look like this:

49.89185 1
53.72692 1
57.82880 1
61.91400 1
214.23345 0
238.11100 0
287.04997 0
379.90897 0


(All the ones from Channel 13 have a 1 in the 2nd column, the ones from Channel 14 have a 0 in the 2nd column)


Here's the code I have sofar:


use diagnostics;


$datafile='monkey6-03.txt';

open(DATA, $datafile);


$/ = "";

while (<DATA>) {

if (index ($_, '"CHANNEL" "13"') > -1)
{ @Array13 = split (/\n/, <DATA>); }


if (index ($_, '"CHANNEL" "14"') > -1)
{ @Array14 = split (/\n/, <DATA>); }

}


$"= "\n";

print "Array 13:\n@Array13\n\nArray 14:\n@Array14\n\n";

push (@Final, map ("$_ 1", @Array13), map ("$_ 0", @Array14));


@Final = sort { $a <=> $b } @Final;

print "FINAL:\n@Final";



But when it prints out the arrays, it just prints the headers like "Final:" but not the numbers underneath. Anybody have any idea what's wrong?