Hi,
I've got a database that includes a postal code.
Now, what I'd like is the following:
A visitor types in his postal code, and then the record with the nearest postal code in the database should be returned.
I found a script that does this more or less, but I don't know how to integrate it in dbman.
Can anybody help?
This is the code:
use strict;
my @stores = ('R2B4T5', 'A1B3X7', 'V6T2A6', 'R7W4W9', 'R7W3E9');
my (@nearest, $lookup);
print "Input your postal code: ";
chomp ($lookup = <STDIN>);
$lookup =~ s/\s+//g;
while ($lookup) {
@nearest = grep /^$lookup/i, @stores;
last if @nearest;
$lookup =~ s/\w$//;
if (@nearest) {
print "The nearest company is:\n";
foreach (@nearest) {
s/(\w{3})(\w{3})/$1 $2/;
print "\t", $_, "\n";
}
else {
print "No stores are close\n";
Thanks,
Lex
I've got a database that includes a postal code.
Now, what I'd like is the following:
A visitor types in his postal code, and then the record with the nearest postal code in the database should be returned.
I found a script that does this more or less, but I don't know how to integrate it in dbman.
Can anybody help?
This is the code:
Code:
#!/usr/local/bin/perl use strict;
my @stores = ('R2B4T5', 'A1B3X7', 'V6T2A6', 'R7W4W9', 'R7W3E9');
my (@nearest, $lookup);
print "Input your postal code: ";
chomp ($lookup = <STDIN>);
$lookup =~ s/\s+//g;
while ($lookup) {
@nearest = grep /^$lookup/i, @stores;
last if @nearest;
$lookup =~ s/\w$//;
if (@nearest) {
print "The nearest company is:\n";
foreach (@nearest) {
s/(\w{3})(\w{3})/$1 $2/;
print "\t", $_, "\n";
}
else {
print "No stores are close\n";
Thanks,
Lex