Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Speeding Up Perl /TK application

Status
Not open for further replies.

Jiggerman

Programmer
Sep 5, 2002
62
GB
hey folks,

I was wondering whether anyone had any tips they could give me on speeding up a Perl/Tk script that I wrote.

The script is basically a version of Excel for Unix (although with limited functionality). It will open up a CSV file and then for each value it will create an Entry box with the value in it. It is specifically made to open CSV files that my department works with these are generally 500 row x 59 column CSV files so they are pretty big.

The problem is that the script works fine, espeacially with tester csv files (20 rows x20 columns) but when it opens a big spreadsheet it takes a long time, and I mean A llllooonnnggggggggg time, although does manage it in the end. the part that slows down the script is listed below.

The problem seems to be creating so many cells, and having to store them, as it gets slower the more rows it creates!

--------Code-------------
Code:
while ($rowNumber < $noOfRows){
	
	
	$columnNumber = 0;
	$firstFlag =1;
	if($rowNumber == 0){createTheHeadingLine();}
		
	while($columnNumber < $noOfColumns){
		

			
		$cellReference = &quot;cell&quot;.$columnNumber.&quot;line&quot;.$rowNumber;
		$cellVariable = $cellReference.&quot;var&quot;;
		$createCell = &quot;\$&quot;.$cellReference.&quot;= \$canvas -> Entry(-textvariable => \\\$&quot;.$cellVariable.&quot;, -width => 11, -relief => 'ridge')\;&quot;;
				eval($createCell);
		if ($@){ #error catching
			print &quot;(create cell) Eval didn't work: $@ \n&quot;;
			undef ($@);
		}
		if ($columnNumber ==0){
			$gridValue = &quot;\$sideCellReference ->grid(\$cell0line&quot;.$rowNumber;
		}elsif($columnNumber > 0){
			$gridValue = $gridValue.&quot;, \$&quot;.$cellReference;
		}
				
			
		$columnNumber++;	
	}
	print &quot;\tstart New Row number $rowNumber\n&quot;;		
		
	$gridValue = $gridValue.&quot;, -sticky => 'nw')\;&quot;;
	#print &quot;\$gridValue = $gridValue\n&quot;;
	eval($gridValue);
	if ($@){
		print &quot;(create grid) Eval didn't work: $@\n&quot;;
		undef ($@);
	}
	undef($evalValue);
	$rowNumber++;	
}
------------------

Thanks for any help
 
You already know $NoOfColumns, can you create a list of that many cells at a time, and append it each time?

It may take less time to create a row than inidividual columns - clutching ...

Just a thought

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
If you mean what I think you mean (the script is creating the spreadsheet column by column rather than row by row) I'm afraid it isn't, but I don't think I got what you meant!

I did have a thought about creating &quot;Swap files&quot;, simce I know it works ok with up to 50 columns, divide the spreadsheet into bouts of 50, and load them in as they are needed, but I'm not perfectly sure how that would work.

Any one have any thoughts

Thanks for any help.
 
Would it be faster to load things into a frame instead of a canvas? You can use Tk::pane and make it a scrolled widget, too.

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Sorry for the delay, I've been on Holiday.

the Pane option does work slightly better, but not nesseserily faster.

The only way that I can think of managing this task is with Swap files, so that less memory is used.

I recon that swapping rows in would be easy enough, but taking them out again would cause problems. This is a wee bit above me i think.

thanks for any/all help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top