MACSCRPT Archives

November 2012

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mark Lively <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 13 Nov 2012 22:32:35 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (47 lines)
On Nov 13, 2012, at 4:15 PM, Bill Steele <[log in to unmask]>
 wrote:

> I have a script that goes through a humungous test file looking for stuff.  Simple version:
> 
> set keywords to {"foo","bar","Fred"}
> set thePieces to splittext bigFile using "whatever"
> repeat with onePiece in thePieces
> 	repeat with oneWord in keywords
> 		if onePiece contains oneWord
> 			(do some stuff with it)
> 		end if
> 	end repeat
> end repeat
> 
> This worked fine until I upgraded to Mountain Lion, and then it started to hang up about halfway through --at different places at different times, with the same file.
> 
> To find out what was happening I put in some display dialogs,and that fixed it.  Replaced the dialogs with one-second delays,and that works too. Seems Applescript Editor needs to stop and think about some things, or maybe clean out some memory when it's doing arrays.
> 
> Any ideas what's happening?
> 
> 

Applescript memory management has never been the best and building massive arrays from massive text files causes problems even in efficient systems.  It is best to deal with things piecewise unless you know you have far more memory than you need.

try this

set lun to open for access "/Users/lively/Documents/Bathroom.ai"
repeat
	try
		set sometext to read lun until "def"
		if sometext contains "%%" then doStuff(sometext)
	on error
		doStuff(sometext)
		exit repeat
	end try
end repeat
on doStuff(aline)
	try
		log (do shell script "echo " & quoted form of aline & "|wc")
	on error
		log aline
	end try
end doStuff

-Mark
Hail hail the gangs all here.

ATOM RSS1 RSS2