Code Comments
Programming Forum and web based access to our favorite programming groups.I have a piece of code that needs to open 31 excel spreadsheets, find
out the row count for each. When it runs it gets about 10 files in
and crashes with an Out of memory error.
Here is an excerpt from the code:
my $oBook;
my $oWks;
my ($iR, $iC, $oWkS, $oWkC);
foreach $hashEntry ( @LOGS )
{
my ( $localfile) =3D $hashEntry->{name};
my ( $err_msg ) =3D ""; # error message variable
my $cmd =3D "";
#
# Get row count of each file, to generate results file
#
$oBook =3D new Spreadsheet::ParseExcel::Workbook->Parse($localfile);
$oWkS =3D ${$oBook->{Worksheet}}[0];
print "------ SHEET: ".$oWkS->{Name}. "\n";
print "Row: ".$oWkS->{MinRow}." v ".$oWkS->{MaxRow}."\n";
$resultMessage.=3Dbasename($localfile).",".$oWkS->{MaxRow}."\n";
}
Is there anything I can do to 'dump' the memory. My initial feeling
is something in ParseExcel, or one of the dependencies isn't playing
nice...or rather I am not letting it play nice through some inaction
or action on my part.
Anyone have some ideas on dealing with this memory problem?
Cheers,
Craig
Post Follow-up to this messageCraig Moynes wrote:
> Hi All,
> I am using the spreadsheet::parseexcel module to open up a series (31)
> spreadsheets and grab the row counts.
>=20
> Here is an excerpt with the ParseExcel Code.
>=20
> my $oBook;
> my $oWks;
> foreach $hashEntry ( @LOGS )
> {
>=20
> my ( $localfile) =3D $hashEntry->{name};
> my ( $err_msg ) =3D ""; # error message
> variable=20
>=20
>=20
> my $cmd =3D "";
>=20
> #
> # Get row count of each file, to generate results file
> #
> $oBook =3D new
> Spreadsheet::ParseExcel::Workbook->Parse($localfile); my
> ($iR, $iC, $oWkS, $oWkC); $oWkS =3D ${$oBook->{Worksheet}}[0];
>=20
> print "------ SHEET: ".$oWkS->{Name}. "\n";
> print "Row: ".$oWkS->{MinRow}." v ".$oWkS->{MaxRow}."\n";
> =20
> $resultMessage.=3Dbasename($localfile).",".$oWkS->{MaxRow}."\n"; }
>=20
> 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.
>=20
No where do I see you closing or destroying the existing data structure. =
I was working on similiar item and only wanted the first row and last colum=
n, but it was loading the whole file in. Forunately one of the Perl gurus p=
rovided a work around, but to get the last row of each Excel file will requ=
ire the loading of the whole file, unless some guru has a work around that =
cheats loading the whole file.
Wags ;)
> Cheers,
> Craig
****************************************
***************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************
***************
Post Follow-up to this messageOn 4/26/05, Wagner, David --- Senior Programmer Analyst --- WGO <David.Wagner@freight.fedex.com> wrote: > Craig Moynes wrote: > No where do I see you closing or destroying the existing data str= ucture. I was >working on similiar item and only wanted the first row and = last column, but it was loading >the whole file in. Forunately one of the P= erl gurus provided a work around, but to get the >last row of each Excel fi= le will require the loading of the whole file, unless some guru has a >work= around that cheats loading the whole file. I thought that by defining the oBook and oWks variables outside the for loop, that the memory for an old object referenced in those variables would be garbage collected when reassigned. Can you paste a code sample for the garbage collection stuff that the gurus supplied you with. Cheers, Craig
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.