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

[MacPerl] AE, checking if file open, memory issues in MacPerl



Hi everybody,

I am attending the discussion on this list for a couple of weeks now
(reading the archived digest) and I'd like to take the opportunity to thank
everybody for their very helpful contributions and to place a couple of
questions/contributions myself.

[1]
The following code snippet intends to make Netscape download a file to disk
(I know I could have MacPerl handle this job all on its own, but since it
is not threaded, I have to wait until a download completes, before I can
move to the next, which can be pretty time consuming - or am I wrong?), but
it doesn't work (although it compiles), obviously to my handling of the fss.

use Mac::AppleEvents;
$url = "http://www.abcde.com";
$file = "Macintosh HD:Desktop Folder:testit.html";
$fss = MacPerl::MakeFSSpec($file);

$be =
AEBuildAppleEvent('WWW!','OURL',typeApplSignature,'MOSS',0,0,"'----':TEXT(\@), I
NTO:fss(\@)",$url, $fss) || die "$!\n";
#$be =
AEBuildAppleEvent('WWW!','OURL',typeApplSignature,'MOSS',0,0,"'----':TEXT(\@), I
NTO:Ò$fssÓ",$url) || die "$!\n"; # no luck here, too

$reply = AESend($be, kAEWaitReply) or die $^E;

print AEPrint($be), "\n";
print AEPrint($reply), "\n";

Thanks to InsideMac, Chris' invaluable AE Tutorial [Thanks Chris!] and
other sample code I figured out quite a couple of things on my own, but I
am stuck on this. Could anyone point me into the right direction? Is there
a way to pass a simple file path of type TEXT instead of a fss?

[2]
Is there a genuine Perl way to determine if a file is open? (Sorry if the
answer is yes and my questions turns into a mere Perl question.) I tried to
figure out how to do it using Mac::Files, but I am stuck there, too. I
guess I could try to open it for writing and handle the error, but that
does not exactyl seem to be the orthodox method. And I could go through an
osax, of course.

[3]
I know that there was a lengthy discussion on MacPerl's memory handling
going on in this list and recently I ran into memory problems myself for
the first time, too.
I wrote a script to batch extract text from html files and put it into one
single file. I used the most recent versions of HTML::Parse and
HTML::FormatText and MacPerl 5.2.0r4. The former are real memory hogs, so I
ran out of memory after only about 20 files were processed (8MB partition;
droplet up to 164k from 64k). I tried undef on every possible location, but
to no avail (yes I know I can not count on garbage collection to occur at a
certain point of time). The odd thing was that after I switched from:
keeping the OUT file handle open from beginning to end of the script to:
closing the OUT handle at the end and reopening it at the beginning of
every file loop, the script could process around 40 files (identical to
those I used on my first try) before MacPerl died. This alone is quite
mysterious to me (BTW the input files were only between 8 and 16 k each,
the output file about 250 k all in all). But what even more astonished me
was that dropping about fifteen files on the droplet at a time, I found
MacPerl coughing up after three cycles again, i.e. memory is obviously not
completely released between executions of a script. Finally I came up with
the following silly AppleScript droplet which passes the about 140 files
dropped on it in bunches of 15 at a time. Furthermore, I changed the script
to quit MacPerl at the end of every round of execution so that AppleScript
has to launch it again.



property perlScript : alias "Macintosh HD:Desktop Folder:html2txt"

on open (theList)
	repeat while length of theList > 0
		set temp to {}
		set i to length of theList
		if i > 15 then
			set j to 15
		else
			set j to i
		end if
		repeat j times
			set temp to temp & item 1 of theList
			set theList to rest of theList
		end repeat
		with timeout of 7 * 60 seconds
			doScript(temp)
		end timeout
	end repeat
end open

on doScript(opts)
	tell application "MacPerl"
		activate
		try
			Do Script ({perlScript} & opts)
		on error errorMessage number errorNumber
			return errorNumber
		end try
	end tell
end doScript



This setup does work, but it is not what I would call an elegant solution.
And I still have no clue about what is going on in MacPerl's memory
partition. Any explanations or, even better, remedies?

Regards,

Peter Hartmann


p.s. This reminds me that someone on the list asked about how to call an
AppleScript droplet from AppleScript with a list of files as argument: I
recently found that this actually works only if the first statement in the
open handler of the droplet is "launch".

Peter Hartmann
Visiting Scholar
Ritsumeikan University, Kyoto, Japan
e-mail:
hartmann@mbox.kyoto-inet.or.jp (preferred)
phv00542@askic.kic.ritsumei.ac.jp




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch