-   Programming (
-   -   Perl: $data[$i]->[$j] problem (

PB0711 05-08-2006 04:17 PM

Perl: $data[$i]->[$j] problem
Thank you in advance.

So here is my code

my $mat ='Matrix.txt';
open MAT, "$mat" or die "Problem opening file, $!\n";
my $huge;
my @listrow;
while (my $line = <MAT>){
        $huge .= $line;
        my @one_row=split(/\t/, $line);
        #print "This is 1 row@one_row \n";
        push @listrow, \@one_row;
my @dim=&DIM($huge); #so col in 0 row in 1
#print $listrow[0]->[3],"\n";
for (my $j=0;$j<=$dim[1];$j++){
        for(my $i=0;$i<=$dim[0];$i++){
                print "i ->$i\tj ->$j\n";
                print " dim is -> @dim\n";
                print $listrow[$j]->[$i],"\t";
        print "\n";
sub DIM {
        my $line = $_[0];
        push my @row, (split /\n/, $line);
        my @arr;
        for (my $t=0; $t < @row; $t++){
                push (@arr, split (/\t/, $row[$t]));
        my @dim = @arr/@row;
        return @dim;# so col in 0 row in 1

So my two questions are this why does the for loop $listrow print out
"Use of uninitialized value in print at line 23."
and is there a better way to find the dimentions.
I know that I can print the matrix using the

way but I don't want to double up on my for loops.



PB0711 05-08-2006 06:06 PM

ok so I looked at it again and it was the for loop. But I would still like some help on finding a better way to get the dimentions of the array. I've probably killed my thread due to my reply taking it off the 0 reply list. :(

DanTaylor 05-08-2006 11:01 PM

Did you mean to assign $j and $t to 0 during each for loop? you probably meant to use ==

PB0711 05-09-2006 12:11 AM

Yea so what it was, was that the dimentions were off and it was tring to go for too long. So == probably would have worked as well. Thank you for the help.

All times are GMT -5. The time now is 03:35 PM.