LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-08-2006, 04:17 PM   #1
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Rep: Reputation: 30
Question Perl: $data[$i]->[$j] problem


Hey,
Thank you in advance.

So here is my code
Code:
my $mat ='Matrix.txt';
open MAT, "$mat" or die "Problem opening file, $!\n";
my $huge;
my @listrow;
while (my $line = <MAT>){
	$huge .= $line;
	chomp($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;
	$dim[1]=@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 test.pl line 23."
and is there a better way to find the dimentions.
I know that I can print the matrix using the
Code:
$data->[$i][$j]
way but I don't want to double up on my for loops.

Cheers

Paul

Last edited by PB0711; 05-08-2006 at 05:18 PM.
 
Old 05-08-2006, 06:06 PM   #2
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Original Poster
Rep: Reputation: 30
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.
 
Old 05-08-2006, 11:01 PM   #3
DanTaylor
Member
 
Registered: Jan 2006
Distribution: Debian Sarge
Posts: 265

Rep: Reputation: 30
Did you mean to assign $j and $t to 0 during each for loop? you probably meant to use ==
 
Old 05-09-2006, 12:11 AM   #4
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Original Poster
Rep: Reputation: 30
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.
 
  


Reply

Tags
matrix, perl, references


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Binary data to be split into ints, shorts and floats ppanyam Programming 1 12-08-2005 05:27 PM
Perl: Inserting new data into the middle of a file R00ts Programming 5 03-07-2005 06:48 PM
make: *** [foomatic-perl-data] Error 1 WilliamS Slackware 8 06-16-2004 10:56 PM
perl->large data structures->copying lackluster Programming 0 08-20-2003 10:27 AM
perl - writing a data structure to a file.. is it possible? paavaka Programming 4 07-14-2001 12:04 AM


All times are GMT -5. The time now is 01:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration