On 4/26/05, Craig Moynes <[EMAIL PROTECTED]> wrote:
> Hi All,
> I am using the spreadsheet::parseexcel module to open up a series (31)
> spreadsheets and grab the row counts.
> 
> Here is an excerpt with the ParseExcel Code.
> 
> my $oBook;
> my $oWks;
> foreach $hashEntry ( @LOGS )
> {
> 
>          my ( $localfile)        = $hashEntry->{name};
>          my ( $err_msg )         = "";           # error message variable
> 
>          my $cmd                 = "";
> 
>          #
>          # Get row count of each file, to generate results file
>          #
>          $oBook = new Spreadsheet::ParseExcel::Workbook->Parse($localfile);
>          my ($iR, $iC, $oWkS, $oWkC);
>          $oWkS = ${$oBook->{Worksheet}}[0];
> 
>          print "------ SHEET: ".$oWkS->{Name}. "\n";
>          print "Row: ".$oWkS->{MinRow}." v ".$oWkS->{MaxRow}."\n";
>          $resultMessage.=basename($localfile).",".$oWkS->{MaxRow}."\n";
> }
> 
> The problem I am running into is after 10 files (in testing all 31 files
> are the same source file with different names), and then I get an out of
> memory error.  Anyone have any idea how I can clean out the memory.  I
> have a feeling it might be some autocaching or something not getting
> cleaned up within ParseExcel.
> 
> Cheers,
>     Craig


$ResultMessage contains a reference to the ParseExcel object, so the
object never goes out of scope, and each iteration through the block
places a new object in memory.  See Persistent Private Variables in
perldoc perlsub, as well as perlboot, etc.  You need to completel
finish with the object before the block exits.  Try,

    $resultMessage.= sprintf("$s,%s\n", basename($localfile), $oWkS->{MaxRow}) ;

or something similar.

HTH,

Jay

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to