welcome: please sign in
location: leo

leo

Ein kleines Perlscript, um dict.leo.org abzufragen. Benoetigt die Perlmodule LWP::Simple und HTML::TableExtract.

# This is under a BSD-Style copyright. I.e. do what you want, as long as you
# give credit. -- Danijel Tasov <dt@vosat.de>

Perl || die;

use LWP::Simple;
use HTML::TableExtract;

die("No Arguments") if(!@ARGV);

$search="@ARGV";
$search=~s/([^\w\d\.\-\_])/sprintf("%%%02x",ord($1))/eig;

$content=get("http://dict.leo.org/?search=$search");

$te = new HTML::TableExtract( depth => 1, count => 3);
$te->parse($content);

foreach $ts ($te->table_states) {
  $c=0;
  foreach $row ($ts->rows) {
     foreach(@$row) {
       s/^\s+//;
       s/\s+$//;
     }
     if($c==0) {
       if((index($row->[0],"ENGLISH") == -1)) {
         print "No results found\n"; exit
       } else {
         printf("%-20s\t%-20s\n",$row->[0],$row->[3]);
         $c++;
         next;
       }
     }
     $output=sprintf("%-20s\t%-20s\n",$row->[1],$row->[3]);
     print $output;
     $c++;
  }
}

leo (last edited 2008-07-14 09:55:46 by localhost)