The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Lingua::ZH::CEDICT::MySQL - MySQL interface for Lingua::ZH::CEDICT

SYNOPSIS

  use Lingua::ZH::CEDICT;

  $dict = Lingua::ZH::CEDICT->new(source   => "MySQL",
                                  host     => "localhost",
                                  port     => "3306",
                                  db       => "dict",
                                  user     => "frederik",
                                  password => "pickeldie",
                                  prefix   => "CEDICT");

  # Connect to MySQL server and search something
  $dict->init();

  $dict->startMatch('house');
  while (my $e = $dict->match()) {
      #      trad    simp    pinyin pinyin w/o tones  english
      print "$e->[0] $e->[1] [$e->[2] / $e->[3]] $e->[4]\n";
  }

  # or import from textfile and store in database for future use
  # (you could also use storable for import)
  $tdict = Lingua::ZH::CEDICT->new{src => "Textfile");
  $dict->importData($tdict);

DESCRIPTION

This module uses a MySQL database to store the dictionary data. Nice for dictionary websites. Check out http://www.web42.com/zidian/ for an example.

METHODS

startMatch($key)

Performs a select on the database and returns an enumerator. You can either use it or call match.

  my $enum = startMatch($key);
  while (my $e = $enum->each()) {
      # ...
  }

If you are surprised by the matches, take a look at the source code to see what the select does.

Note that it is your responsibility to ensure that the key doesn't contain malicious input. I suggest using something like

  $key =~ s/[^\p{L}\w\d]//g;

(This requires perl 5.6.1)

match()

Provided for compatibility with the other modules. Uses the enumerator generated by startMatch.

PREREQUISITES

Net::MySQL for the connections to MySQL.

Lingua::ZH::CEDICT. (Although you can choose to circumvent it for performance reasons).

AUTHOR

Christian Renz, <crenz@web42.com>

LICENSE

Copyright (C) 2002 Christian Renz. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Lingua::ZH::CEDICT. Net::MySQL. http://www.web42.com/zidian/