简体   繁体   中英

Perl SQLite dictionary

How do we Insert dictionary into SQLite database using perl scripting?

I found this for unix platform

http://developeronline.blogspot.in/2008_04_01_archive.html

but it doesn't work on windows. I have strawberry perl and SQLite installed on my machine. Can someone help me how we create a dictionary with perl ?

When saying "I found this", it's good to point to the particular post you're trying to show us, not a page containing many posts. I think the actual post you're talking about is this one .

And it's horrible code; written by someone who clearly knows very little about Perl.

You say that it's written for Unix. That seems unlikely given that it's a Microsoft article and the use of cls confirms that it's aimed at Windows environments. But (as CL points out in a comment above) ones that have the wget program installed.

Rewriting the code to something that approximates real Perl gives this:

use strict;
use warnings;

use LWP::Simple;

my $message = "\nPlease enter a word to look for:\n>";

print $message;

while (<>) {
  chomp;
  if ($_ eq "<") {
    system("cls");
    print $message;
  } else {
    print "Connecting..";
    my $url = "http://wordnetweb.princeton.edu/perl/webwn?s=$_";
    my $page = get $url;

    if ($page =~ /<\s*b>$word<\/b>[^\(]+\(([^\)]*)\)/) {
      print "\n#def#$1";
    }
  }
}

I've switched to using the LWP::Simple module rather than wget as it seems silly to use an external module for this. I've also had to change the URL, as the address had changed in the seven years since the article was written.

This version works, but it still needs to be cleaned up a lot. In particular, scraping information from a web site like this is fragile (and often goes against the terms and conditions of the web site that you're scraping). It would be a far better idea to look for an API that dives you the same information.

Update: If you want to load the dictionary into a database, then the best approach would be to download the source files and parse those.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM