MySQL FULLTEXT + Ngram
MySQL FULLTEXT + Ngram : LIKE検索より数十倍高速な、お手軽 日本語全文検索 について
http://www.tatamilab.jp/rnd/archives/000390.html
Perl , PHP のN-gram変換用モジュール配布中
MySQL FULLTEXT + Ngram : LIKE検索より数十倍高速な、お手軽 日本語全文検索 について
http://www.tatamilab.jp/rnd/archives/000390.html
Perl , PHP のN-gram変換用モジュール配布中
ヘッダはこのようにしたほうがいいようです
Content-Type: text/plain; charset = "ISO-2022-JP"
↓
Content-Type: text/plain; charset="iso-2022-jp"
さくらのWEBメールで文字化けしていました。
use Jcode;
use Net::SMTP;
#--------------------------------------
sub sendmail {
(my $SMTPserver,my $from,my $to,local $subj,local $body) = @_;# 引数の受信
my $SMTP;
# オブジェクトの作成
$SMTP = Net::SMTP -> new( $SMTPserver, # SMTPサーバー名を指定
Hello => $SMTPserver, # SMTPドメイン名を指定
Timeout => 60); # 接続待ち許容時間(秒)
#ヘッダ部の組み立て
$SMTP -> mail($from); # 送信元メールアドレスを指定
$SMTP -> to($to); # 宛先メールアドレスを指定
$subj = jcode($subj)->mime_encode();
#メールのヘッダーを構築
$header = << "MAILHEADER";
From: $from
To: $to
Subject: $subj
Mime-Version: 1.0
Content-Type: text/plain; charset = "ISO-2022-JP"
Content-Transfer-Encoding: 7bit
MAILHEADER
#メール本文
$message = << "__HERE__" ;
$body
__HERE__
#文字コードをJISに変換
$message = jcode($message,'euc')->jis;
#データ部の組み立て
$SMTP -> data();
$SMTP->datasend("$header\n");
$SMTP->datasend("$message\n");
$SMTP -> dataend(); # データ終端、メール送信
$SMTP -> quit; # SMTP接続の終了
}
こんな風にして使う
&sendmail($mail_server, $mail_from, $mail_to, $mail_subj, $mail_body);
# wget http://nchc.dl.sourceforge.net/sourceforge/opencvlibrary/opencv-1.0.0.tar.gz
# tar xvzf opencv-1.0.0.tar.gz
# cd opencv-1.0.0
# ./configure
# make
# make install
/etc/profile に記述
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# export LD_LIBRALY_PATH=/usr/local/include/opencv
# wget http://search.cpan.org/CPAN/authors/id/J/JI/JIRO/Image-ObjectDetect-0.11.tar.gz
# tar xvzf Image-ObjectDetect-0.11.tar.gz
# cd Image-ObjectDetect-0.11
# perl MakeFile.PL
# make
# make install
hash を配列に格納する場合は \ をつける
my $self = {
docfields => \%docfields,
};
取り出す際
my %docfields = %{$self->{docfields}};
#!c:\perl\bin\perl
#!/usr/bin/perl
use strict;
use warnings;
use IO::Handle;
use Data::Dumper;
use XMLRPC::Lite;
use File::Basename;
{
my $blogid = "ブログID";
my $username = "ユーザー名";
my $password = "パスワード";
my $proxyurl = "ブログのXMLRPC先";
# 画像パス
my $filename = "C:/images/xxxx.jpg";
my $bits = read_bin_file ($filename);
#
# ここで画像を投稿する
# いまのところ1枚単位
#
my $picresult = XMLRPC::Lite
-> proxy($proxyurl)
-> call('metaWeblog.newMediaObject', $blogid, $username, $password,
{
'bits' => XMLRPC::Data->type('base64', $bits),
'type' => "image/jpeg",
'name' => basename($filename)
}
)
-> result;
if (!defined ($picresult))
{
die "failed $!";
}
else
{
#
# 本文の投稿
#
my $msgresult = XMLRPC::Lite
-> proxy($proxyurl)
-> call('metaWeblog.newPost', $blogid, $username, $password,
{
'title' => "this is the title",
'description' => "and this is\n\n" .
"the body and a link to the picture\n\n" .
"{'url'} . "\">\n\nthe end :-)\n",
'mt_allow_comments' => 1, # must be int, not string
'mt_allow_pings' => 1 # must be int, not string
# 'mt_convert_breaks' => "", # string, see mt.supportedTextFilters for a valid value
# 'mt_text_more' => "", # the extended entry
# 'mt_excerpt' => "",
# 'mt_keywords' => "",
# 'mt_tb_ping_urls' => ??, #array of strings, ping URLs
},
1 # 1 = publish
)
-> result;
if (!defined ($msgresult))
{
die "failed $!";
}
else
{
print Dumper ($msgresult);
}
}
}
sub read_bin_file
{
my ($filename) = @_;
#--------------------
# read in the picture
my $fh = IO::Handle->new();
open($fh, $filename) or die "$!";
local($/) = undef; # slurp
binmode($fh);
my $bits = <$fh>;
close($fh);
return $bits;
}
use WWW::Mechanize;
my $img_url = "画像URL";
my $w = WWW::Mechanize->new();
$w->get($img_url,":content_file"=>"保存するファイル名");
http://archive.apache.org/dist/perl/ ここから最新版をダウンロードする
tar xzf mod_perl-2.0-current.tar.gz
cd mod_perl-2.0.3
perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
make
make test
make install
httpd.conf に追加
LoadModule perl_module modules/mod_perl.so
Apache 再起動
ChasenのperlモジュールのText::Chasenを通常通りインストールするとエラーになる
Can't load '/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/auto/Text/ChaSen/ChaSen.so' for module Text::ChaSen: /usr/lib/libchasen.so.0: undefined symbol: _ZNSs4_Rep11_S_terminalE at /usr/lib/perl5/5.8.6/i386-linux-thread-multi/DynaLoader.pm line 230.
Makefile.PLを以下のように修正する
'NAME' => 'Text::ChaSen',
'VERSION_FROM' => 'ChaSen.pm',
'LIBS' => ['-lchasen']
,'LD' => "c++" ←これを追加
);
perl Makefile.pl
make
make install
サンプル例
#!C:\Perl\bin\perl
#モジュールのロード
use Log::Log4perl;
use Log::Dispatch::FileRotate;
#設定ファイル定義 &10秒ごとに設定ファイルを読む
$conf = "./log4perl.conf";
Log::Log4perl::init_and_watch($conf,10);
#設定値で初期化する
#Log::Log4perl::init_and_watch('./log4perl.conf');
#オブジェクト定義
$logger = Log::Log4perl->get_logger();
$logger -> debug( 出力したい文字列 );
設定ファイル例
log4perl.category = DEBUG,FR1 #FR1のレベル定義
log4perl.appender.FR1 = Log::Dispatch::FileRotate #モジュール指定
log4perl.appender.FR1.filename = logfile.log #ログファイル名指定
log4perl.appender.FR1.mode = append #書き出し指定
log4perl.appender.FR1.size = 200 #ファイルサイズ KBを整数で指定する
log4perl.appender.FR1.max = 5 #世代数設定
log4perl.appender.FR1.layout = PatternLayout
log4perl.appender.FR1.layout.ConversionPattern = %d %P %p %r %H %F %L %C - %m%n
詳しくは
http://log4perl.sourceforge.net/
ppm コマンドで行う場合
ppm repo add log4perl http://log4perl.sourceforge.net/ppm
ppm install Log-Log4perl
ppm install Log-Dispach
ppm install Log-Dispach-FileRotate
ppmコマンドは ppm help で詳細確認
CPAN install Log::Log4perl
perl -MCPAN -e 'install Log::Log4perl' でインストール
test.pl
#!/usr/bin/perl
#!C:\Perl\bin\perl
use Log::Log4perl;
# 設定ファイルの読み込み
Log::Log4perl::init('./log4perl.conf');
# 設定ファイルに定義したloggerを生成
my $logger = Log::Log4perl::get_logger("mylogger");
#infoやらdebugやらで出力する
$logger->info("this is INFO message");
$logger->debug("this is DEBUG message");
設定ファイル 同じディレクトリに置く
log4perl.conf
log4perl.logger.mylogger = DEBUG, FileAppndr1
log4perl.appender.FileAppndr1 = Log::Log4perl::Appender::File
log4perl.appender.FileAppndr1.filename = debug.log
log4perl.appender.FileAppndr1.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.FileAppndr1.layout.ConversionPattern = %d %F(%L) [%p] %m %n
perl test.pl
debug,logの名前でこんな風に出力されればOK
2007/09/06 18:57:16 log4.pl(10) [INFO] this is INFO message
2007/09/06 18:57:16 log4.pl(11) [DEBUG] this is DEBUG message
配列の長さは@[配列名]
$week[0] = 'Sun';
$week[1] = 'Mon';
$length = @week; #配列の長さが入る
print $length;
for($i=0;$i<@week;$i++){
print $week[$i];
print "\n";
}
XML::RSSだけ より LWP::UserAgent を使ったほうが確実です
use strict;
use XML::RSS;
use LWP::Simple;
my $url = 'http://blog.livedoor.com/xml/blog_ranking_cat.rdf';
my $dat = get($url);
foreach my $item ( @{$rss->{'items'}} ) {
print $item->{'link'};;
print decode('utf-8',$item->{'title'});
}
=====================================================================
use strict;
use XML::RSS;
use XML::XPath;
use LWP::Simple;
use LWP::UserAgent;
my $url = 'http://blog.livedoor.com/xml/blog_ranking_cat.rdf';
my $dat = get($url);
my $rss = new XML::RSS;
my $ua = LWP::UserAgent->new;
$rss= $ua->get($url);
my $list = $rss->decoded_content();
my $parser = new XML::XPath->new(xml => $list);
my @items = $parser->findnodes("/rdf:RDF/item");
foreach my $item (@items){
echo $parser->findvalue("link", $item)->value();
echo $parser->findvalue("title", $item)->value();
}
install_driver(mysql) failed: Can't load '/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.14:
共有オブジェクトファイルを開けません: そのようなファイルやディレクトリはありません
/usr/lib/perl5/5.8.6/i386-linux-thread-multi/DynaLoader.pm line 230, line 855.
at (eval 720) line 3
Compilation failed in require at (eval 720) line 3, line 855.
Perhaps a required shared library or dll isn't installed where expected
こういう場合のエラー。
MySQLをソースからインストールするとこういうエラーが起こるようです。
/etc/ld.so.conf がRPMでインストールした場合のmysqlのパスを見に行っているようです。
もともとMySQLはRPMでインストールするように本家サイトで推奨されていましたので・・・
なのでソースでインストールした先 ーこの場合は/usr/local/mysql になりますー を見に行くように設定します。
# vi /etc/ld.so.conf
ここに /usr/local/mysql/lib/mysql を追加します。
RPM版MySQLのほうを見に行っている記述があればコメントアウトします。
コマンドで設定を反映させます。
# ldconfig
ロリポップではこうなった
ここをクリック
#!/usr/bin/perl
use strict;
use CGI;
my $q = CGI->new;
my @modules = ();
foreach my $base_dir ( @INC ) {
my @dir = ( undef );
while ( @dir ) {
my $dir = pop @dir;
my $open = $base_dir;
$dir and $open .= "/$dir";
opendir ( DIR, $open );
my @object = grep { !/^\./ } readdir ( DIR );
closedir ( DIR );
push @dir, map { "$dir/$_" } grep { -d "$base_dir/$dir/$_" } @object;
push @modules, map { "$dir/$_" } grep { /\.pm$/ } @object;
}
}
map { s/^\/// } @modules;
my %modules = map { $_=>1 } @modules;
@modules = sort keys %modules;
my $modules = {};
foreach ( @modules ) {
my @temp = split /\//;
my $eval = '$modules->'.join('->',map{ '{"'.$_.'"}' }@temp).'= 1;';
eval $eval;
}
print $q->header;
print $q->start_html(-title=>'modules in this Perl.');
print hashref2list($modules);
print $q->end_html;
sub hashref2list {
my $hashref = shift;
my $parent = shift;
my @keys = keys %{$hashref};
my @file = ();
my @dir = ();
foreach ( @keys ) {
if ( ref $hashref->{$_} ) {
push @dir, $_;
} else {
push @file, $_;
}
}
@dir = sort @dir;
map { s/\.pm$// } @file;
@file = sort @file;
return $q->ul(
$q->li([map { "$parent$_" } @file]),
$q->li([map { $_.'::'.hashref2list($hashref->{$_}, $parent.$_.'::') } @dir])
);
}
exit(0);
Can't exec "mysql_config": No such file or directory at Makefile.PL ・・・
/usr/local/mysql/bin/mysql_config --libs
で、吐き出されたデータをメモ。
/usr/local/mysql/bin/mysql_config --cflags
で、吐き出されたデータをメモします。
CPANでインストール途中だったソースのあるディレクトリに移動します。
cd /root/.cpan/build/DBD-mysql-4.004/
perl Makefile.PL --cflags=-I/us
r/local/mysql/include/mysql "--libs=-L/usr/local/mysql/lib/mysql
-lmysqlclient -lz -lcrypt -lnsl -lm"
これでMakeファイルが生成されます。
その後は
make
make test
make install
CGIでエラーをブラウザに表示するにはCGI::Carpモジュールを使う
use CGI::Carp qw(fatalsToBrowser);
この1行をいれておくだけ。
こんな風にエラーが表示されます。
Software error:
Can't locate XML/Agent.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.6/i386-linux-thread-multi /usr/lib/perl5/5.8.6 .) at test.pl line 7, line 846.
BEGIN failed--compilation aborted at test.pl line 7, line 846.
For help, please send mail to the webmaster (admin@heteml.jp), giving this error message and the time and date of the error.
sub hiragana2katakana {
local($_) = @_;
s/\xa5\xa4/`/g;
s/\xa4([\xa1-\xfe])/\xa5$1/g;
s/`/\xa5\xa4/g;
$_;
}
$katakana = hiragana2katakana($hiragana);
Testing handle creation speed...
9523 NullP sth/s perl 5.008006 darwin-thread-multi-2level (gcc 3.3 -Os) 0.000105s
test.pl done
/usr/bin/make test -- OK
Running make install
Manifying blib/man1/dbiproxy.1
Warning: You do not have permissions to install into /usr/local/man/man1 at /System/Library/Perl/5.8.6/ExtUtils/Install.pm line 114.
mkdir /usr/local/man/man3: Permission denied at /System/Library/Perl/5.8.6/ExtUtils/Install.pm line 112
make: *** [pure_site_install] Error 255
/usr/bin/make install -- NOT OK
一般のユーザーでインストールするとこんな風になるようです。
sudo cpan で行うとうまくいきます。
All tests successful, 1 test skipped.
Files=4, Tests=567, 23 wallclock secs ( 5.62 cusr + 12.00 csys = 17.62 CPU)
/usr/bin/make test -- OK
Running make install
Installing /System/Library/Perl/5.8.6/darwin-thread-multi-2level/auto/DB_File/DB_File.bundle
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /System/Library/Perl/5.8.6/darwin-thread-multi-2level/DB_File.pm
Installing /System/Library/Perl/5.8.6/darwin-thread-multi-2level/auto/DB_File/autosplit.ix
Installing /usr/share/man/man3/DB_File.3pm
Writing //System/Library/Perl/5.8.6/darwin-thread-multi-2level/auto/DB_File/.packlist
Appending installation info to //System/Library/Perl/5.8.6/darwin-thread-multi-2level/perllocal.pod
/usr/bin/make install -- OK
ftp://ftp.cpan.org/pub/CPAN/src/
ここからperl-5.8.8.tar.gzをダウンロードします
tar xvzf perl-5.8.8.tar.gz
sudo chown -R $User:wheel perl-5.8.8
cd perl-5.8.8
./configure
make
sudo make install
/usr/local/bin/perlにインストールされるので現在のperlと置き換えます
/usr/bin/perl -v
/usr/local/bin/perl -v
mv /usr/bin/perl /usr/bin/perl_org
sudo mv /usr/bin/perl /usr/bin/perl_org
sudo ln -snf /usr/local/bin/perl /usr/bin/perl
perl -v
This is perl, v5.8.8 built for darwin-2level
Copyright 1987-2006, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
AJAXをシンプルに使うライブラリがリリースされています。
05年末ごろにJavaのクラス内部のメソッドをJavaScriptで呼び出せるAPIがリリースされています。
PHPに限って言えばそんなことができるようです。
Sajax.phpを呼び出した後に関数を定義してやればJavascriptでコールできるようです。
詳しくはサンプルを参照
http://www.modernmethod.com/sajax/
windows環境でも成功しました
よくあるブログの記事をgmailに転送するやつ。
私の場合、ポイントはNet::SSLeyのコンパイルがうまくいっていない点でした。
OpenSSLを http://www.slproweb.com/products/Win32OpenSSL.html ここから持ってきたり
Linuxサーバーのほうでコンパイルしたのもをコピーしたりしながら
ようやくできました。
config.yaml はこのとおりです
global:
plugin_path:
- C:\Perl\site\lib\Plagger\Plugin
assets_path: C:\Perl\site\lib\Plagger\assets
timezone: Asia/Tokyo
log:
level: info
cache:
base: C:\plagger
plugins:
- module: Subscription::Config
config:
feed:
- http://blog.bulknews.net/mt/index.rdf
- module: Publish::Gmail
config:
mailto: 自分のGmailアドレス
mailfrom: 自分のGmailアドレス
mailroute:
via: smtp_tls
host: smtp.gmail.com:587
username: 自分のGmailアドレス
password: 自分のパスワード
これでGmailアカウントでログインしてメールを飛ばします
Linuxの場合はこんな感じ
global:
plugin_path:
- /usr/local/lib/perl5/site_perl/5.8.8/Plagger/Plugin
assets_path: /usr/local/lib/perl5/5.8.8/Plagger/assets
timezone: Asia/Tokyo
log:
level: info
cache:
base: C:\plagger
plugins:
- module: Subscription::Config
config:
feed:
- http://blog.bulknews.net/mt/index.rdf
- module: Publish::Gmail
config:
mailto: 自分のGmailアドレス
mailfrom: 自分のGmailアドレス
mailroute:
via: smtp_tls
host: smtp.gmail.com:587
username: 自分のGmailアドレス
password: パスワード
windows の場合、libxml/parser.h がないというエラーでコンパイルできないことがあります。
そのような場合 http://www.zlatkovic.com/pub/libxml/ ここから
iconv-1.9.2.win32.zip libxml2-2.6.27.win32.zip ダウンロード&展開後、
C開発環境bin, include, lib のそれぞれの場所に解凍後ディレクトリの該当する部分をすべてコピーします。
私の場合、このディレクトリのbin, include, lib のコピーしました。
C:\MicrosoftVisualStudio\VC98
cpan -i XML::SAX
cpan -i XML::LibXML::Common
cpan -i XML::Libxml
nmake install -- OK が出れば成功です
RH9にインストールできなかったときのメモ
XML::LibXML に適したlibxml2がないというエラーが出ていました。
このときのバージョンは 2.6.11 でした。
http://xmlsoft.org/ ここから libxml2-2.6.26.tar.gz をダウンロードします
tar xvzf libxml2-2.6.26.tar.gz
cd libxml2-2.6.26
./configure --prefix=/usr
make
make install
rpm では依存性のエラーがでましたのでソースからコンパイルしました
cpan -fi XML::SAM
cpan -fi XML::LibXML::Common
cpan -fi XML::LibXML
All tests successful, 44 subtests skipped.
Files=32, Tests=1766, 3 wallclock secs ( 3.03 cusr + 0.25 csys = 3.28 CPU)
/usr/bin/make test -- OK
Running make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Writing /usr/local/lib/perl5/site_perl/5.8.8/i686-linux/auto/XML/LibXML/.packlist
Appending installation info to /usr/local/lib/perl5/5.8.8/i686-linux/perllocal.pod
/usr/bin/make install -- OK
できた!
Windows の場合
C:\Perl\cpan\build\Plagger-0.7.17\ あたりにある
assets をフォルダごとPerlのライブラリパスが通っているところに配置しないとだめっぽいです
私はこのディレクトリの下にコピーしました
C:\Perl\lib\Plagger
cpan -fi XML::Parser で
最後に expat.h がないためにインストールできないメッセージがでたので
APACHE_HOME/include 以下の expat.h をPathの通っているところにコピーしてコンパイル
いくつかのCPANモジュールでWindowsにCコンパイル環境がなかったため
エラーになっておりました
そのため マイクロソフト C++ Visual Studio Express Editions をインストールしました。
こちらから無料でダウンロード&インストールできます。
またユーザー登録をすれば30日以上使えます。
http://www.microsoft.com/japan/msdn/vstudio/express/visualc/
*SQLサーバーは入れておりません 最小限のインストールです
インストールが終わったら "cl.exe"、"nmake.exe"のあるディレクトリまでPathを通します。
C:\MicrosoftVisualStudio8にインストールした場合
Path に追加 : C:\MicrosoftVisualStudio8\VC\bin;C:\MicrosoftVisualStudio8\Common7\IDE;
include に追加 : C:\MicrosoftVisualStudio8\VC\lib
lib に追加 : C:\MicrosoftVisualStudio8\VC\lib;C:\MicrosoftVisualStudio8\SDK\v2.0\Lib
その後、Microsoft Platform SDK もインストールします
http://www.microsoft.com/japan/msdn/vstudio/express/visualc/usingpsdk/
サイト上の解説のほかに
Include に追加 : C:\Program Files\Microsoft Platform SDK\Include\crt;C:\Program Files\Microsoft Platform SDK\Bin\win64;
*sys/types.h , MSVCR80.dll がみつからないエラーを防ぎます
http://www.microsoft.com/japan/msdn/netframework/downloads/default.aspx
cpan > install Bundle::CPAN
これで -fi ( force install ) が使えるようになします
cpan -fi Plagger
しかしこれでもCコンパイル環境がうまく動きませんでしたので
ファイル交換ツールでゲットしたVisual C++ をインストールしています。
インストール後、環境変数Pathに
C:\VC98\Bin;C:\VC98\Lib;C:\VC98\Include を追加しています。
話題のPlaggerをインストールしてみました
単純にこんな感じw
Active Perlインストール済み端末でプロンプトを立ち上げる
C:\>ppm
ppm> rep add tcool http://ppm.tcool.org/server/ppmserver.cgi?urn:PPMServer
と打ち込むとこんな風に表示される
[1] ActiveState Package Repository
[2] tcool
そのあとに
ppm> search Plagger と打ち込むと
Searching in Active Repositories
1. Plagger [0.7.9] Pluggable RSS/Atom Aggregator
2. Plagger [0.7.9] Pluggable RSS/Atom Aggregator
こんな風に表示されます
その後に
ppm> install Plagger
とやれば1時間ぐらいでインストールされます
Successfully installed Plagger version 0.7.17 in ActivePerl 5.8.8
うまくいかないときは
Bundle::CPANをインストールしてみましょう。
もしくは
ppm> force install Plagger
メール送信系ではsendmail へのパスを修正しないといけない場合が多い
#$SendmailCmnd = '/usr/lib/sendmail -n -t';
#$SendmailCmnd = '/usr/sbin/sendmail -n -t';
$SendmailCmnd = '/usr/sbin/sendmail -t -i';
こんな順番で修正
Windows の場合
ppm install Plagger 又は CPAN install Plagger
Linux の場合
perl -MCPAN -e 'Plagger'
-----------------------------------------
__ ___
(_ _|_ ._ ._ | o ._ _ _
__) |_ | |_) | | | | | (/_
|
-----------------------------------------
Perlモジュールを使ってエクセルファイルを作ります
ソースはこんな感じ。
設定を変えればPostgreSQL, MySQL 両方で使えます
#!C:\Perl\bin\perl
#!/usr/local/bin/perl
use strict;
use DBI;
use Jcode;
use Spreadsheet::WriteExcel;
use DBIx::DBSchema;
#設定
my $DSN = 'dbi:mysql:DB名:サーバー名';
my $DB_USER = 'ユーザー名';
my $DB_PASSWD = 'パスワード';
my $XLS_FILE = '出力ファイル名';
my $dbh = DBI->connect($DSN, $DB_USER, $DB_PASSWD) or die $DBI::errstr;
my $xls = Spreadsheet::WriteExcel->new($XLS_FILE);
my $schema = new_native DBIx::DBSchema $dbh;
for my $table ($schema->tables()) {
my $work = $xls->addworksheet("$table");
$work->write(0, 0, 'INDEXES');
my $index_ref = $dbh->selectall_arrayref("SHOW INDEX FROM $table");
write_worksheet($work, $index_ref, 1);
$work->write(3 + $#{$index_ref}, 0, 'COLUMNS');
my $column_ref = $dbh->selectall_arrayref("DESCRIBE $table");
write_worksheet($work, $column_ref, 4 + $#{$index_ref});
}
$dbh->disconnect;
sub write_worksheet {
my($work, $ref, $offset) = @_;
for my $row (0 .. $#{$ref}) {
for my $col (0 .. $#{$ref->[$row]}) {
$work->write($row + $offset, $col, $ref->[$row]->[$col]);
}
}
}
Windows XPでのお話
>cpan
>install DBI
>install DBD::mysql
ここでなせがエラーが出て先に進まなくなった。
なのでここから DBD-mysql-3.0002.zipをダウンロードしてインストールすることに
http://ppm.activestate.com/PPMPackages/zips/8xx-builds-only/Windows/
ppm install C:\download\DBD-mysql-3.0002\DBD-mysql.ppd
できたっぽい
某社の専用サーバーにMT 3.2 を入れようとしたところ
Image::Magick がないといわれてCPANでのインストールもアーカイブからのビルドも失敗したので
ImageMagick のインストールから行いました。
[root@www ImageMagick-6.1.8]# make
cd . && /bin/sh /usr/local/src/ImageMagick-6.1.8/missing --run autoconf
configure.ac:15: error: Autoconf version 2.59 or higher is required
configure.ac:15: the top level
autom4te: /usr/bin/m4 failed with exit status: 1
make: *** [configure] エラー 1
こんな風になってしまうのでautoconfのインストールから行います
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz
tar xvzf autoconf-2.60.tar.gz
cd autoconf-2.60
./configure --prefix=/usr
make
make check
make install
wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar xvzf jpegsrc.v6b.tar.gz
./configure
make
make install
unzip ImageMagick-6.1.8-7.zip
cd ImageMagick-6.1.8
./configure
make
make install
tar xvzf PerlMagick-6.24.tar.gz
cd PerlMagick-6.24
perl Makefile.PL
ls
make
make install
perl 5.8.8 の下で実行
プロンプトを立ち上げて
ppm
ppm > repository add Theoryx5 http://theoryx5.uwinnipeg.ca/ppms/
ppm > install Task-Catalyst
ppm > search Catalyst::Model::DBIC
ppm > install 1
ppm > install DBD::SQLite2
ppm > install Data-Uniqid
ppm > install Catalyst::Plugin::Prototype
ppm > install Catalyst::Plugin::Session
ppm > quit
Config.pmに書かれています
find / -name Config.pm
vi /usr/local/lib/perl5/5.8.8/CPAN/Config.pm たとえばこういうところ
'urllist' => [q[ftp://ftp.dti.ad.jp/pub/lang/CPAN/]],
ここ
ダウンロードがうまくいかないときはここのURLを書き換えます
Perl 5.8.8 インストール後、
perl -MCPAN -e 'install Module::Find'
perl -MCPAN -e 'install Path::Class'
perl -MCPAN -e 'install Task::Catalyst'
すべてデフォルトで
プラグインインストールで止まる場所があれば 個別でインストールする
*iptables は止めてインストールしたほうが早いです
終わったら必要に応じてプラグインをインストール
perl -MCPAN -e shell
install Catalyst::Helper
install DBI::DBD
install DBD::mysql
install DBIx::Class::Schema::Loader
install Bundle::LWP
install Catalyst::Helper::Model::DBIC::Schema
install Catalyst::Helper::View::TT
install Catalyst::Model::DBIC::Schema
install Catalyst::Plugin::Charsets::Japanese
install Catalyst::Plugin::FillInForm
install Catalyst::Plugin::Prototype
Catalystをインストールしていると ここで止まった
CPAN.pm: Going to build S/SR/SRI/Catalyst-Plugin-HTML-Widget-1.1.tar.gz
*** Module::AutoInstall version 1.01
*** Checking for dependencies...
[Core Features]
- Catalyst ...missing. (would need 5.5)
- HTML::Widget ...missing.
試しに単体でCatalyst-Plugin-HTML-Widget-1.1.tar.gzを持ってきて
perl Make.pl したらどうもPerlのバージョンが5.8以上でないとだめっぽい
そこでperl 5.8.8 をインストールすることにした
http://www.perl.com/download.csp#stable ここからstable.tar.gz をダウンロード
tar xvzf stable.tar.gz
cd perl-5.8.8
すべてデフォルトでインストール
sh Configure -Dprefix=/usr/local/perl -de && nice -19 make && make test
make install
これでOK
/usr/local/bin/perl -v で確認
現在のものとパスを入れ替える
mv /usr/bin/perl /usr/bin/perl_org
ln -s /usr/local/bin/perl /usr/bin/perl
/etc/profile.d/perl5.8.sh を作成
vi /etc/profile.d/perl5.8.sh
#!/bin/sh
PERL_PATH=/usr/local/bin/perl
if [ ! -d "$PERL_PATH" ] ;then
export PERL5LIB=$PERL_PATH/lib
export PATH=$PERL_PATH/bin:$PATH
fi
ログインしなおして perl -v で確認
Javaみたいに使えるメール送信pmを組んでみました
使う場合はこんな風に
use Function::mail;
Function::mail::setSubject("題名");
Function::mail::setBody("本文");
Function::mail::setFromAddress("aaa@aaa.co.jp");
Function::mail::setToAddress("bbb@bbb.co.jp");
Function::mail::send();
pm は続き
リクエストの種別を判定して下記のようにすれば
GETでもPOSTでも同じように取得できるっぽいです
if($ENV{'REQUEST_METHOD'} eq "GET"){
$buffer = $ENV{'QUERY_STRING'} . '&';
@pairs = split(/&/,$buffer);
}elsif ($ENV{'REQUEST_METHOD'} eq "POST"){
$length = $ENV{'CONTENT_LENGTH'};
read(STDIN, $buffer, $length);
@pairs = split(/&/,$buffer);
}
foreach $pair (@pairs){
($name,$value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$param_value{$name} = $value;
}
$param_value{'変数名'} で value を取得
XML::RSS と LWP::Simple を使えばすごく簡単にできます
#!C:\Perl\bin\perl
#!/usr/bin/perl
use strict;
use Jcode;
use Encode;
use LWP::Simple;
use XML::RSS;
my $rss = new XML::RSS;
my $url = "http://www.nikkeibp.co.jp/index.rdf";
my $dat = get($url);
$rss->parse($dat);
my $channel = $rss->{'channel'};
print "Content-type: text/plain; charset=UTF-8\n\n";
print $channel->{'title'};
print "
";
print "
";
foreach my $item( @{$rss->items}){
print $item->{'title'};
print "
";
print $item->{'link'};
print "
";
if( $item->{'description'} ){
print $item->{'description'};
print "
";
print "
";
}
}
exit;
EUCの場合
sub check(){
if ($_[0] =~ /[\x80-\xFF]/) {
#全角
return "全角";
}
}
文字列に全角文字が含まれているかチェック
サブルーチンを作ってみた
## YYYY-MM-DD hh:mm:ss を返す
sub getNowDateTime{
my ($sec,$min,$hour,$mday,$mon,$year,$wno) = localtime(time);
return sprintf("%04d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec);
}
ついでにもうひとつ
#ランダムな文字列を返す
sub getRandStr {
#文字数の指定
my $value = shift;
my @chara = qw(a b c d e f g h i j k l m n o p q r s t u v w z y x z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z );
my $str;
if( $value eq "" ){
$str.=$chara[int(rand($#chara+1))] for ( 1..16 );
}else{
$str.=$chara[int(rand($#chara+1))] for ( 1..$value );
}
return $str;
}
my @list = ("自民党", "民主党" ,"公明党" ,"共産党" ,"社民党");
↑これより
my @list = qw(自民党 民主党 公明党 共産党 社民党);
↑こんな風にしたほうがいいです
print $ist[$i]; のときにちゃんと値が取得できます hashXXXXにならない
ActivePerl をダウンロード
http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl
Windows MSI
ダウンロード後、ダブルクリックしてインストール
デフォルトではC:\Perlにインストールされるので
C:\Perl\bin をコマンドパスに追加する
Apache httpd.conf 修正
Options Indexes FollowSymLinks MultiViews ExecCGI Includes
*MultiViews と ExecCGI と Includes を追加します。
AddHandler cgi-script .cgi .pl
AddHandler send-as-is asis
AddHandler imap-file map
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
AddType text/html .html (記述追加)
AddOutputFilter INCLUDES .html (記述追加)
Windows Perl実行環境へのDBIモジュールの追加
ppmコマンドを使います
Dosプロンプトでppmと打ち込むと
C:\Perl>ppm
PPM - Programmer's Package Manager version 3.1.
Copyright (c) 2001 ActiveState SRL. All Rights Reserved.
Entering interactive shell. Using Term::ReadLine::Stub as readline library.
Type 'help' to get started.
このあとに
ppm> install DBI
====================
Install 'DBI' version 1.50 in ActivePerl 5.8.8.817
====================
Downloaded 513616 bytes.
Extracting 69/69: blib/arch/auto/DBI/Driver_xst.h
Installing C:\Perl\site\lib\auto\DBI\dbd_xsh.h
Installing C:\Perl\site\lib\auto\DBI\DBI.bs
Installing C:\Perl\site\lib\auto\DBI\DBI.dll
Installing C:\Perl\site\lib\auto\DBI\DBI.exp
Installing C:\Perl\site\lib\auto\DBI\DBI.lib
Installing C:\Perl\site\lib\auto\DBI\dbipport.h
Installing C:\Perl\site\lib\auto\DBI\dbivport.h
Installing C:\Perl\site\lib\auto\DBI\DBIXS.h
Installing C:\Perl\site\lib\auto\DBI\dbi_sql.h
Installing C:\Perl\site\lib\auto\DBI\Driver.xst
Installing C:\Perl\site\lib\auto\DBI\Driver_xst.h
Installing C:\Perl\html\bin\dbiprof.html
Installing C:\Perl\html\bin\dbiproxy.html
Installing C:\Perl\html\site\lib\DBI.html
Installing C:\Perl\html\site\lib\Bundle\DBI.html
Installing C:\Perl\html\site\lib\DBD\DBM.html
Installing C:\Perl\html\site\lib\DBD\File.html
Installing C:\Perl\html\site\lib\DBD\Proxy.html
Installing C:\Perl\html\site\lib\DBD\Sponge.html
Installing C:\Perl\html\site\lib\DBI\Changes.html
Installing C:\Perl\html\site\lib\DBI\DBD.html
Installing C:\Perl\html\site\lib\DBI\FAQ.html
Installing C:\Perl\html\site\lib\DBI\Profile.html
Installing C:\Perl\html\site\lib\DBI\ProfileData.html
Installing C:\Perl\html\site\lib\DBI\ProfileDumper.html
Installing C:\Perl\html\site\lib\DBI\ProxyServer.html
Installing C:\Perl\html\site\lib\DBI\PurePerl.html
Installing C:\Perl\html\site\lib\DBI\W32ODBC.html
Installing C:\Perl\html\site\lib\DBI\Const\GetInfoReturn.html
Installing C:\Perl\html\site\lib\DBI\Const\GetInfoType.html
Installing C:\Perl\html\site\lib\DBI\Const\GetInfo\ANSI.html
Installing C:\Perl\html\site\lib\DBI\Const\GetInfo\ODBC.html
Installing C:\Perl\html\site\lib\DBI\DBD\Metadata.html
Installing C:\Perl\html\site\lib\DBI\ProfileDumper\Apache.html
Installing C:\Perl\html\site\lib\DBI\SQL\Nano.html
Installing C:\Perl\html\site\lib\Win32\DBIODBC.html
Files found in blib\arch: installing files in blib\lib into architecture depende
nt library tree
Installing C:\Perl\site\lib\DBI.pm
Installing C:\Perl\site\lib\Bundle\DBI.pm
Installing C:\Perl\site\lib\DBD\DBM.pm
Installing C:\Perl\site\lib\DBD\ExampleP.pm
Installing C:\Perl\site\lib\DBD\File.pm
Installing C:\Perl\site\lib\DBD\NullP.pm
Installing C:\Perl\site\lib\DBD\Proxy.pm
Installing C:\Perl\site\lib\DBD\Sponge.pm
Installing C:\Perl\site\lib\DBI\Changes.pm
Installing C:\Perl\site\lib\DBI\DBD.pm
Installing C:\Perl\site\lib\DBI\FAQ.pm
Installing C:\Perl\site\lib\DBI\Profile.pm
Installing C:\Perl\site\lib\DBI\ProfileData.pm
Installing C:\Perl\site\lib\DBI\ProfileDumper.pm
Installing C:\Perl\site\lib\DBI\ProxyServer.pm
Installing C:\Perl\site\lib\DBI\PurePerl.pm
Installing C:\Perl\site\lib\DBI\W32ODBC.pm
Installing C:\Perl\site\lib\DBI\Const\GetInfoReturn.pm
Installing C:\Perl\site\lib\DBI\Const\GetInfoType.pm
Installing C:\Perl\site\lib\DBI\Const\GetInfo\ANSI.pm
Installing C:\Perl\site\lib\DBI\Const\GetInfo\ODBC.pm
Installing C:\Perl\site\lib\DBI\DBD\Metadata.pm
Installing C:\Perl\site\lib\DBI\ProfileDumper\Apache.pm
Installing C:\Perl\site\lib\DBI\SQL\Nano.pm
Installing C:\Perl\site\lib\Win32\DBIODBC.pm
Installing C:\Perl\bin\dbiprof
Installing C:\Perl\bin\dbiprof.bat
Installing C:\Perl\bin\dbiproxy
Installing C:\Perl\bin\dbiproxy.bat
Successfully installed DBI version 1.50 in ActivePerl 5.8.8.817
同じようにして
install DB_Fiel
install DBD-MySQL
install DBD-SQLite
エンジニアの価値が決まる「構造化プログラミング」についての特集号です!
それとは別にライブドアのシステム構築の詳細な解説記事もあります。
実際に稼動している大規模システムの構築・運営ノウハウが公開されるなんてまずないですよ!
これを機にぜひ読んでみましょう。
WEB+DB PRESS Vol.33
Movable Type をインストールすると・・・
# mt.cgi
Content-Type: text/html
Got an error: Unsupported driver MT::ObjectDriver::DBM: Can't locate DB_File.pm in @INC (@INC contains: ./extlib ./lib /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at lib/MT/ObjectDriver/DBM.pm line 9.
BEGIN failed--compilation aborted at lib/MT/ObjectDriver/DBM.pm line 9.
Compilation failed in require at (eval 3) line 1.
BEGIN failed--compilation aborted at (eval 3) line 1.
DB_File.pmが入っていないみたいだ
しかしこれはコマンドラインからインストールできる
perl -MCPAN -e shell
We have to reconfigure CPAN.pm due to following uninitialized parameters:
cpan_home, keep_source_where, build_dir, build_cache, scan_cache, index_expire, gzip, tar, unzip, make, pager, makepl_arg, make_arg, make_install_arg, urllist, inhibit_startup_message, ftp_proxy, http_proxy, no_proxy, prerequisites_policy, cache_metadata
/usr/lib/perl5/5.8.0/CPAN/Config.pm initialized.