[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Memory probs



Running the enclosed script on a folder containing about 20 or so HTML files I get an out of memory error after about ten or so, I tried using MaxMem() to reclaim some of the memory back but to no avail (perhaps I misunderstand it's use).

Is there something I can optimise in the script so that I don't run out of memory so fast, or is my only alternative to increase the memory allotted to MacPerl?

tech specs: MacPerl 5.2.0r4 with 15Mb of memory + Performa 5430 OS8.6

#!perl



# FILE: "HTML2Text.pl"
# created: 09/8/99 {9:39:30 pm}
# last update: 10/8/99 {3:02:40 am}


#---------------------------------------------------------

#----------- declare includes
use strict;
use diagnostics-verbose;
use HTML::Parse;
use HTML::FormatText;
use Mac::Files;
use Mac::Memory;

#----------- declare variables
my (@files,$file,$text,$dirIN,$pathOUT,$count,$fileOUT);


$dirIN="Path:to:spurce:folder";
$pathOUT="path:to:destination:folder";

print "reading from \"$dirIN\"...\n";
opendir(DIR, $dirIN) || die "cannot open \"$dirIN\":- $!";
#grep for HTML files
@files = grep(/.html$/ , readdir(DIR));
closedir(DIR);
print"..done reading.\n\n";

chdir($pathOUT);
print"moved to destination folder:",`pwd`,"\n";

#find out how many files there are
$count=$#files+1;
print "there are $count files to process\n";
open (OUT, ">>$fileOUT")|| die"can't open \"$fileOUT\":- $!";
foreach $file(@files){
$fileOUT=$file;
$fileOUT=~s/.html$//;
print OUT "$fileOUT\n\n";
print "printing $fileOUT to file\n";
open (IN, "<$dirIN$file");
print "..parsing orignal \"$file\"...\n";
while(<IN>) {
$text = HTML::FormatText->new->format(parse_html($_));
print OUT $text;
}
$text="";
print "..done with \"$fileOUT\"\n",--$count," files left to process\n\n";
printf ("\n\nFree Memory = %0.2f Mb\t" , mbytes(FreeMem()));
printf ("Max Memory = %0.2f Mb\n" , mbytes((MaxMem())[0]));
close (IN);
MacPerl::SetFileInfo('CWKJ', 'TEXT', $fileOUT);
}


print "-=-"x20,"\n","finished\n";



#----------- subroutine separator

sub mbytes {$_[0]/(1024**2) };