Mark 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. 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. > > 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. >
I don't think you need to do a lot of typing. your best approach(i think of course) is to use the zip code as key and the zone code id as value. if you use the other way around, you are bound to find your searching algr. slow becasue you have to search through tons of zip codes on each search. try: #!/usr/bin/perl -w use strict; my %zips; @zips{100..200} = map{'zone 1'} (100..200); @zips{201..300} = map{'zone 2'} (201..300); @zips{301..400} = map{'zone 3'} (301..400); while(<STDIN>){ exit if(/^exit/i); chomp; print "$_ is in $zips{$_}\n" if(exists $zips{$_}); } __END__ run: 100 100 is in zone 1 300 300 is in zone 2 400 400 is in zone 3 123 123 is in zone 1 exit david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]