in reply to Foreach Loop Optimization

Perhaps the slowness you observe is in memory usage instead of the foreach loops. Instead of loading the entire file up into @project_module_list, read only one line of the file at a time. Replace your outer foreach loop with the following while loop and see if it improves.

open FH, "<database.txt" or die; <FH>; # ignore header line of CSV file while ( my $project_module_list = <FH> ) { chomp $project_module_list; ## put remainder of code here }

Replies are listed 'Best First'.
Re^2: Foreach Loop Optimization
by upallnight (Sexton) on Aug 01, 2007 at 16:13 UTC
    Thanks, I thought of that but I need to do a lot of sorting, filtering, and other stuff with the table data before I print it so I would have to load it all into memory any way.
      If that's the case then you might try some of the techniques in Dominus's lightweight database tutorials. You can find the link to them in this node:

      http://www.perlmonks.com/?node_id=629253

      I started looking through the materials and I think it may work real well for your situation. However, I do not have much experience in it, so you're on your own from there.