Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a sub-routine in AppleScript to get text from a file and insert that text in a list of lists forming a dictionary.

Text File:

a:b
c:d
e:f

Expected list:

{{"a", "b"}, {"c", "d"}, {"e", "f"}}

Here's my code:

on getDictionary(filePath)
    set dictionary to {}
    set dictionaryFile to paragraphs of (read POSIX file filePath)
    repeat with entry in dictionaryFile
        set AppleScript's text item delimiters to {":"}
        set delimitedEntry to every text item of entry
        copy delimitedEntry to the end of dictionary
    end repeat
    return dictionary
end getDictionary

I'm wondering if this is a good approach for my goal. It does produce the desired result.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.