Dear all,
I need to read a data file containing 96 records/lines
and each record/line contains several columns
separated by tab. I would like to extract the first
column from each record only and put them into a 12x8
array. Here is the script I use to do the job but it
seems I have some problems with the loop to build a
12x8 array(I just get a one-dimenstion array only).
Any comments?
Thanks,
Li
script:
#!c:/Perl/bin/perl.exe
use warnings;
use strict;
my $array=[];
my $filename="TXT.001";
open (FH, $filename) or die "$filename can't be
opened";
for (my $row=0;$row<8;++$row){
for (my $column=0;$column<12;++$column){
while (my $line=<FH>){
if ($line=~/CPM/){next;}# remove header line
else{
my @array=split("\t",$line); #split
each record/line into an array
#shift @array;
#remove the 1st element from the array
my $column1=shift @array; #get the
second element from the array
print
$array->[$row][$column]=$column1, "\t"; #populate
the 12x8 array
}
}
}
print "\n";
}
here is the format of file to be read:
CPM
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12
11 12 13
12 13 14
13 14 15
14 15 16
15 16 17
16 17 18
17 18 19
18 19 20
.........
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>