

| データ作成 | mkybdata.pl |
| 検索CGI | ybks.cgi |
wget http://www.post.japanpost.jp/zipcode/dl/kogaki/lzh/ken_all.lzh lha x ken_all.lzh nkf -e ken_all.csv | mkybdata.pl > ybdata mkary ybdata
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
my @c = split(/"?,"?/, $_);
die if (@c != 15);
$c[8] =~ s/以下に.+$/*/;
print $c[2]." ".join("", @c[6,7,8])."\n";
}
※ワンライナーでいいじゃん、というレベル。汎用性なし。
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use SUFARY;
my $ybdata = "/home/yto/ybks/ybdata";
my $suf = SUFARY->new($ybdata);
my $q = new CGI;
my $key = $q->param('key') || "";
print $q->header(-charset => 'EUC-JP');
print $q->start_html(-title=>'郵便番号検索 ybks');
print $q->h1('郵便番号検索 ybks');
print $q->startform(-method => 'GET', -name => 'myform'),
$q->textfield('key'), $q->submit('search'), $q->endform;
search_and_print($suf, $key) unless ($key =~ /^\s*$/);
print $q->end_html(), "\n";
sub search_and_print {
my ($suf, $key) = @_;
my @res = $suf->search($key);
print "<pre>", scalar(@res), "件見つかりました。\n\n";
for my $i (0..$#res) {
if ($i == 999) {
print "\nヒット数が多いのでここまで!\n";
last;
}
my $str = $suf->get_line($res[$i]);
$str =~ s!($key)!<span style="background-color:pink">$1</span>!g;
printf "<b>%3d</b>. %s", $i + 1, $str;
}
print "</pre>";
}
※現在のバージョンでは検索キーワードを複数含む住所は、複数回表示さ