#!/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 iata(iata,icao,airport) VALUES(?,?,?);"); $|=1; my ($letter,$iata,$icao,$airport); foreach $letter ("A".."Z") { my $rdsoure=$cmd . " http://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_$letter|"; print "$letter"; # $rdsoure="B.txt"; open (RDPIPE, $rdsoure) || die "Can't open $rdsoure for reading: $!\n"; my $flag=0; while () { if ($flag==0) { $flag++ if (/\*\ IATA/); } elsif ($flag==1) { if (/^\s+\*\ (\w+)\ (\(\w+\))?\ ?-\ \[\d+\](.+)$/) { $iata=$1; $icao=$2; $airport=$3; $icao =~ s/\(|\)//g; $airport =~ s/\[\d+\]//g; $sth->execute($iata,$icao,$airport); # $sth->execute($dbh->quote($iata),$dbh->quote($icao),$dbh->quote($airport)); } elsif (/^\s+Retrieved/) { $flag++; } } } close RDPIPE; } print "\n"; $sth->{Active} = 1; $sth->finish(); undef $sth; $dbh->commit; $dbh->disconnect();