------------------------------------------------
On Tue, 19 Nov 2002 11:41:09 -0500, "mark" <[EMAIL PROTECTED]> wrote:

> 
> I want to be able to determine what zone a zip code falls in from a user
> input.  Once I write the hash, the data contained within it will remain
> unchanged throughout the script except maybe for the occasional update if
> things change.
> 
> I am just unsure of which approach would be the best or if I have any real
> choice. 

There is always choice, that is why this is Perl ;-)...

> I have already written a hash that contains all of the possible
> zips in this format:
> 
> %zone = {
> one => [370,422,490..500,etc.]
> two => [200..232,388,etc]
> three => [and so on]
> four => [and so forth]
> }
> 
> I am assuming that I will be able to load an array of each of the zones and
> test if the zip is is contained within that zone.
>

You are correct you can do it this way. You would simply 'each' your hash, getting 
your key and an arrayref, then you could 'grep' through each of the arrays referenced 
by your arrayref for the particular zip.
 
> OR
> 
> I could list each zip with it's corresponding zone into a hash with each zip
> and zone paired together, but I think that will take an awful lot of typing.

Yes you could, and yes it would. Although you could code the algorithm you used to 
generate the arrays only have it generate the hash keys (zips) with the zone as the 
value just as you did in your head when you generated what you have.  Or you might 
consider storing it to a file that can be quickly and easily updated outside of your 
logic (though this will slow things down slightly because it will require an 'open', 
etc. and if you are going to go this far then why not use a database, but taht is 
another discussion)...

> 
> I am wondering which way would be best as far as server load or if the
> difference would be worth considering.  It's much easier for me to use the
> zone as the name component and a list of integers and ranges of integers for
> the value component.

The memory usage should be roughly the same I would imagine as the deciding factor is 
still the number of zips and in both cases you have the same number.  Looking up into 
a hash is optimized as is grepping through the arrays so I would imagine the load is 
probably about the same, it really comes down to what is easier to code, what is 
easier to maintain, unless you REALLY need this optimized.

> 
> Is it acceptable to use ranges(this..that,that..this) in the value or name
> component of a relational array?
> 

This is something else you might consider, just stepping through the logic with each 
zip rather than storing all zips into memory.    In other words if your zones are 
based on numerical, say zone eight is every zip from 84556 to 90201 ;-) then why not 
just say if (($zip >= 84556) && ($zip <= 90201)) {}  as this is very optimized. Or 
even storing this kind of logic into an array of logic strings that can then be evaled 
to decide whether a zip matches if it is that complex.

In many locations programmer and maintenance time is more costly than processor/memory.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to