Alpha DevCon 2018
Results 1 to 8 of 8

Thread: Programming Puzzle 17 - Import Madness #1

  1. #1
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,299

    Default Programming Puzzle 17 - Import Madness #1

    Importing Raw Data


    Your manager has returned from her vacation. You quickly learn that
    while she was relaxing at South Beach (Miami) she's been
    thinking of ways to improve your xbasic programming skills. It's
    comforting to know that she was thinking of you, but ...

    In any case here's your assignment grasshopper:

    Create a contacts table with the following field specifications:

    First name, length of 35
    Last name, length of 60
    Address 1, length of 55
    Address 2, length of 55
    City, length of 30
    State, length of 2
    Zip Code, length of 5

    Prepend your initials to "_Contact.dbf" as the table name.
    For example my initials are TEC. My table will be called TEC_Contact.dbf

    Import the data contained in IM_1.csv (attached) into your table.

    IM_1.csv is a comma seperated values table.
    The File layout is given as the first line of the file.
    Disclosure Notice: the data in IM_1.csv was exported from the Customer table of AlphaSports.

    INSTRUCTIONS
    a) Write an xbasic script that will create the table, open the data (CSV) file, and import it into the table. Naturally, the script must correctly parse each line of the CSV file, assigning the desired column values
    to the correct fields in each record of your table.

    b) Your script should check to see if the table already exists, and get permission from your user before doing the import if the table already exists.

    c) The import need not overwrite existing table records, nor does it need to replace matching table records.

    d) Export your script and attach your solution to a reply here.

    ps. If you like this puzzle thank Andy Schone who thought it up. Thanks, Andy!
    Last edited by Tom Cone Jr; 07-14-2011 at 07:17 PM.

  2. #2
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    490

    Default Re: Programming Puzzle 17 - Import Madness #1

    Here is my solution.

    SPP_Import_Madness_1.txt
    Stephen Pilon
    Associate Librarian
    Christendom College

  3. #3
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,044

  4. #4
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    490

    Default Re: Programming Puzzle 17 - Import Madness #1

    I like these puzzles because I learn so much about efficiency. The first rule of efficiency seems to be:

    RULE 1: A shorter script is not necessarily a faster script.

    My somewhat succinct script took about 177 seconds against a list of 10,000 names, whereas Andy's took less than two seconds!
    Stephen Pilon
    Associate Librarian
    Christendom College

  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,299

    Default Re: Programming Puzzle 17 - Import Madness #1

    Stephen, that's right.

    It's useful to watch for statements that invoke activity on the hard disk. Opening and closing a table is one of the slowest things our machines do. Doing that over a network connection is even slower. When writing a script that will enter a batch of new records it's usually much faster to open the target table once, enter the records one right after the other, and then close the table. The alternative ( open table, enter record, close table, then open table, enter record 2, close table, then open table, enter record3, then close table, etc and so on ) is always going to be slower.

    Make sense?

    -- tom

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,299

    Default Re: Programming Puzzle 17 - Import Madness #1

    And, here's a 3rd approach. Uses older, lower level functions to parse each line, and enter records to the target table.

    -- tom

  7. #7
    Member
    Real Name
    Jeb Richardson
    Join Date
    Aug 2011
    Location
    Bowling Green, KY
    Posts
    26

    Default Re: Programming Puzzle 17 - Import Madness #1

    puz 17 attempt

    puz 17.txt

  8. #8
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,044

    Default Re: Programming Puzzle 17 - Import Madness #1

    Nicely done Jeb

    Go ahead and put some comments in it and you should be good to go.

    I didn't test it, I am assuming it will work correctly as the flow and code looks strangely familiar.

Similar Threads

  1. Programming Puzzle 2 - Another Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 16
    Last Post: 12-20-2014, 10:38 AM
  2. Programming Puzzle 1 - Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 32
    Last Post: 12-26-2011, 01:38 PM
  3. Programming Puzzle 3 - Fractions, anyone?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 11-08-2011, 05:40 AM
  4. Programming Puzzle 11 - More Loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 11
    Last Post: 08-20-2011, 04:50 PM
  5. Programming Puzzle 7 - Yet another nested loop!
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 4
    Last Post: 08-08-2011, 05:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •