Re: Reversing the lines in a file[speed, stack overflow}
Re: Reversing the lines in a file[speed, stack overflow}
- Subject: Re: Reversing the lines in a file[speed, stack overflow}
- From: Cornwall <email@hidden>
- Date: Fri, 10 May 2002 09:02:59 -0700
At 7:15 AM -0400 5/10/02, Paul Skinner wrote:
>
set textInput to read file ((choose file) as text) as list using delimiter return
>
set fileRef to open for access file ((((path to the desktop) as text) & "Resultr") as text) with write permission
>
set AppleScript's text item delimiters to return
>
write ((the reverse of textInput) as text) to fileRef
>
close access fileRef
This thread was a bit of a 'wake up' for me. For several years I have used the construction "paragraphs of (read theFile)" rather than the seemingly slower "read theFile as list using delimiter return"
set theFil to choose file
set t1 to current date
repeat 60 times
set textInput to paragraphs of (read theFil)
set txtOut to ((the reverse of textInput) as text)
end repeat
set t2 to current date
set ET to t2 - t1
-->5
But - at somewhere between 4000 and 4500 lines, it errors with a 'stack overflow' error. I guess I had never tried it with such large a file.
Although slower, Paul's example does not error in that fashion (I tested up to about 6000 lines).
set theFil to choose file
set t1 to current date
repeat 60 times
set textInput to read file ((theFil) as text) as list using delimiter return
set AppleScript's text item delimiters to return
set txtOut to ((the reverse of textInput) as text)
end repeat
set t2 to current date
set ET to t2 - t1
-->30
Why does the first example error when the second does not?
Corny
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.