--- /dev/null
+#!/usr/bin/perl
+
+binmode(STDOUT, ":utf8");
+
+use LWP::UserAgent;
+use HTML::Entities;
+use Encode;
+
+sub yplookup {
+ my($tel);
+ ($tel) = @_;
+
+ $ua = LWP::UserAgent->new;
+ $ua->agent("tel2name/1.0 ");
+ $res = $ua->request(HTTP::Request->new("GET", "http://www.eniro.se/query?what=yp&search_word=$tel"));
+
+ return undef unless $res->is_success;
+
+ $html = $res->content;
+
+ match: while($html =~ /<span\s+class\s*=\s*"org fn"\s*>\s*([^<]*[^\s<])\s*<\/span>/ig) {
+ $match = decode_entities($1);
+ for $prev (@matches) {
+ next match if $prev eq $match;
+ }
+ push @matches, $match;
+ }
+ for $match (@matches) {
+ print "$match\n";
+ }
+}
+
+sub wplookup {
+ my($tel);
+ ($tel) = @_;
+
+ $ua = LWP::UserAgent->new;
+ $ua->agent("tel2name/1.0 ");
+ $res = $ua->request(HTTP::Request->new("GET", "http://www.eniro.se/query?what=wp&phone_number=$tel"));
+
+ return undef unless $res->is_success;
+
+ $html = $res->content;
+
+ match: while($html =~ /<a\s+class\s*=\s*"fn expand"[^>]*>\s*\<span\>\s*([^<]*[^\s<])\s*<\/span>/ig) {
+ $match = decode_entities($1);
+ for $prev (@matches) {
+ next match if $prev eq $match;
+ }
+ push @matches, $match;
+ }
+ for $match (@matches) {
+ print "$match\n";
+ }
+}
+
+$tel = $ARGV[0];
+
+if(open NT, $ENV{"HOME"} . "/phone/nametab") {
+ while(<NT>) {
+ if(/$tel\s(.*)$/) {
+ print "$1\n";
+ exit 0;
+ }
+ }
+ close NT;
+}
+
+$yppid = open YP, "-|";
+if($yppid == 0) {
+ yplookup $tel;
+ exit 0;
+}
+$wppid = open WP, "-|";
+if($wppid == 0) {
+ wplookup $tel;
+ exit 0;
+}
+binmode(YP, ":utf8");
+binmode(WP, ":utf8");
+
+match: while(<YP>) {
+ chomp;
+ for $prev (@matches) {
+ next match if $prev eq $_;
+ }
+ push @matches, $_;
+}
+match: while(<WP>) {
+ chomp;
+ for $prev (@matches) {
+ next match if $prev eq $_;
+ }
+ push @matches, $_;
+}
+
+for $match (@matches) {
+ print "$match\n";
+}