• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to parse CSV
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to parse CSV


  • Subject: Re: How to parse CSV
  • From: Neil Faiman <email@hidden>
  • Date: Thu, 24 Jan 2008 07:36:13 -0500

On Jan 23, 2008, at 11:17 AM, Skeeve wrote:

The AppleScript is
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
on run
set started to current date
set {oAStid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "|"}
set LoL to {}
repeat with rec in every paragraph of convert(choose file)
copy text items of rec to the end of LoL
end repeat


  ...

1st Scenario: Seconds elapsed 5 => 80 lines / Second
2nd Scenario: Seconds elapssed 4345 => 2.3 lines / Second

There's a known bug, dating back into the darkest pre-history of AppleScript, that when you append to a list this way, AppleScript ends up copying the list anyway, so what looks like an O(N) loop is actually O(N^2). The standard hack for working around it and getting the expected O(N) performance is to make the list a property of the script rather than a local variable of the handler: thus,


on run
property LoL : {} -- this line is the secret
set started to current date
set {oAStid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "|"}
set LoL to {}
repeat with rec in every paragraph of convert(choose file)
copy text items of rec to the end of LoL
end repeat


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: How to parse CSV
      • From: Skeeve <email@hidden>
References: 
 >Re: How to parse CSV (From: Benedikt Quirmbach <email@hidden>)
 >Re: How to parse CSV (From: Skeeve <email@hidden>)

  • Prev by Date: Re: CGI automatic download file
  • Next by Date: Mail.app Attachments Filter
  • Previous by thread: Re: How to parse CSV
  • Next by thread: Re: How to parse CSV
  • Index(es):
    • Date
    • Thread