spewn
Programmer
- May 7, 2001
- 1,034
i have a file with a zip code on each line. my script pulls a user's information, including a field that includes a zip code, as well as other elements of an address ($addrField). i need to compare the zip code from that field against each zip code in the file, and note if it matches. i also search a field with a numeric value ($zipField), and i check it against that, too.
the script i have works fine. if i search 1 zip code, everything runs perfect. but once i open it up to the whole db, it seems to overwhelm the script, because it shows 0 that match, not even the 1 from earlier.
anyways, here's the script:
is there a better way to accomplish my goal? Seems to give me incorrect results when the zipFile.txt has thousands of lines. would it be better to put the zips in a variable? then search the variable?
appreciate any ideas. thanks!
- g
the script i have works fine. if i search 1 zip code, everything runs perfect. but once i open it up to the whole db, it seems to overwhelm the script, because it shows 0 that match, not even the 1 from earlier.
anyways, here's the script:
Code:
$ismatch=false;
open(MYINPUTFILE, 'zipFile.txt');
while(<MYINPUTFILE>) {
$line = $_;
chomp($line);
if (($zipField eq $line)||(($addrField =~ /$line/))) {$ismatch=true;}
}
is there a better way to accomplish my goal? Seems to give me incorrect results when the zipFile.txt has thousands of lines. would it be better to put the zips in a variable? then search the variable?
Code:
$ismatch=false;
$zipFile=25685,12549,52365,89655,36415,75896,32548,78512,25025,01458...'; #with thousands of zips
@zparry=(/,/,$zipFile);
foreach $line (@zparry) {
chomp($line);
if (($zipField eq $line)||(($addrField =~ /$line/))) {$ismatch=true;}
}
appreciate any ideas. thanks!
- g