#!/usr/bin/perl use strict; use English; use DBI; my $dbh = DBI->connect("dbi:SQLite:iata.db","","", { RaiseError => 1, AutoCommit => 0 }); my $cmd="lynx --dump -width=2000"; my $sth = $dbh->prepare("REPLACE INTO tn(code,airport) VALUES(?,?);"); $|=1; my $letter; foreach $letter ("A".."Z") { my $rdsoure=$cmd . " http://www.travelnotes.org/Airports/airport-codes_" . $letter .".htm|"; print "$letter"; # $rdsoure="A.htm"; open (RDPIPE, $rdsoure) || die "Can't open $rdsoure for reading: $!\n"; my $flag=0; while () { if ($flag==0) { $flag++ if (/Major\ Airports/); } elsif ($flag==1) { s/\[\d+\]//g; if (/^\s+(\w{2,3})\ --\ (\w+.*)$/) { # print "$1;$2;\n"; $sth->execute($1,$2); } elsif (/Airlines\ of\ the\ World/) { $flag++; } } } close RDPIPE; } print "\n"; $sth->{Active} = 1; $sth->finish(); undef $sth; $dbh->commit; $dbh->disconnect();