Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Zip code into region with 30,000 zip codes


I need to assign respondents to one of 5 groups based on their zip code. The list of qualifying zip codes is nearly 30,000, so when I implement a free format question with the following to categorize respondents, the survery times out on me. Is there another option to accomplish this?

Free format:
<input name="Zip_region" id="Zip_region" type="hidden" value="
Begin Unverified Perl
my $Zip_region=0;

if (VALUE("Q326")=="15536") {$Zip_region=5;}

elseif (VALUE ("Q326")=="16689") {$Zip_region=5;}

etc.... for the ~30,000 zips

Thanks in advance
asked Jan 23 by anonymous
I haven't ran any performance tests, but a few thoughts come to mind:

First, pull the VALUE function out of the conditional, like this:

my $zip = VALUE("Q326");
if ($zip == ...) { ... }
elsif ($zip == ...) { ...}

Second, you might get a small boost if you define your comparison values as numbers instead of as strings.  Just need to get rid of the quotation marks around those zip codes.

2 Answers

0 votes
Doing this using  perl will surely hang the system. We have resolved this by utilizing  external database in past.

I created a table with two column - zip code and region.

In survey, when respondent enters zip code, a query is triggered and returns the corresponding region. Takes no more than a second.
answered Jan 24 by Saurabh Aggarwal Gold (30,135 points)
The solution provided by Zachary did cause a server timeout.  I am unfamiliar with how to use an external database. Could you point me in the right direction? This sounds like exactly what I need.

Thank you!
0 votes
I think you should try a Perl hash.  For example:

begin unverified perl

#This is a Hash.  
#It offers a quick way to look up keys and return values.
my %ZipHash = (     
    "98382" => 1,
    "84627" => 1,
    "84049" => 2,
    "84032" => 2

my $Zip_region = $ZipHash{VALUE("zipcode")};

end unverified
answered Jan 25 by Justin Luster Silver Sawtooth Software, Inc. (6,950 points)