我正在尝试为我在SourceForge上托管的字典项目编写自动完成功能.
不幸的是,SF上的Perl没有安装
JSON模块.如何在不使用模块本身的情况下解决此问题?作为模特我拿了
JQuery UI automcomplete guide on jensbits.
这是Perl代码,用于查询文本并发送到自动完成模块
#!/usr/bin/perl
use strict;
use CGI;
use DBI;
use JSON;
# HTTP HEADER
print "Content-type: application/json; charset=iso-8859-1\n\n";
my $dbh = DBI->connect("DBI:mysql:database;mysql_read_default_file=/path/.my.cnf");
$dbh->do("set character set utf8");
$dbh->do("set names utf8");
my ($p, $sth, @query_output);
$p = new CGI;
my $term = $p->param('term');
$sth = $dbh->prepare(qq{SELECT trim(both char(13) FROM article) AS value, definition FROM dict WHERE article like ?;});
$sth->execute('%'.$term.'%');
# LOOP THROUGH RESULTS
while ( my $row = $sth->fetchrow_hashref ){
push @query_output, $row;
}
#CLOSE THE DATABASE CONNECTION
$dbh->disconnect()
# JSON OUTPUT
print JSON::to_json(\@query_output);