Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Out of memory and While replacements with excel XLSX application

by marquezc329 (Scribe)
on Oct 08, 2012 at 09:00 UTC ( #997784=note: print w/ replies, xml ) Need Help??


in reply to Out of memory and While replacements with excel XLSX application

As anonymous before me stated, use subroutines to break up your program into smaller more manageable chunks. Then try to optimize each segment. Not only will this get you closer to solving your problems and more than likely eliminate alot of the memory usage along the way, but it will allow you to post a more concentrated chunk of code that is more likely to attract the attention of the monks.

From perlfaq3:

     "When it comes to time-space tradeoffs, Perl nearly always prefers to throw memory at a problem. Scalars in Perl use more memory than strings in C, arrays take more than that, and hashes use even more."

You have created an enormous amount of temporary scalars that are all named very similarly (i.e.  $c1..$c39) and used in very repetitive code. To start off, maybe try creating a subroutine to handle those more efficiently.
sub extract { my @arrays = (\@right, \@legal, \@prod); foreach 1..39 { foreach my $col ($_) { next unless defined $Sheet->Cells($row, $col)->{'Value'}; my $c = $Sheet->Cells($row, $col)->{'Value'}; map {push @$_, $c} @arrays; } } }

This is just an example, but I'm sure if you go through your program you'll be able to find multiple situations where things can be cut down and made faster, simpler, and easier to maintain/read.
It might do you well to clean up your comments, and include a sample of the data you plan on working with before making a post like this. It'll increase the likelihood that you'll get help from the guys that know most. You might try reading How (Not) To Ask A Question. Good Luck!


Comment on Re: Out of memory and While replacements with excel XLSX application
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-09-01 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (6 votes), past polls