Perlのプログラムのエラーです。ローカルでは問題なく動きました。サー
Perlのプログラムのエラーです。ローカルでは問題なく動きました。サーバはさくらサーバで文字コードはEUC-JPです。
CGIから文章をMECAPIという形態素解析APIに送って、品詞ごとにファイルに書き込みます。
Status: 500 Content-type: text/html
Software error:
Can't locate object method "content" via package "HTTP::Response=HASH(0x86e9250)" (perhaps you forgot to load "HTTP::Response=HASH(0x86e9250)"?) at test9.cgi line 49.
#!/usr/local/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use Encode qw/encode decode/;
use utf8;
use CGI;
use CGI::Carp qw( fatalsToBrowser);
my $str;
my $i;
my $j;
&main;
sub main{
my $q = new CGI();
$str = $q->param( "words" );
$str = decode('euc-jp', $str);
my $title = encode('euc-jp', "MeCab APIを呼出す");
my $h1 = encode('euc-jp', $str . "の品詞");
print $q->header( -type =>"text/html", -charset => "euc-jp" );
print "<meta http-equiv=\"refresh\" content=\"5;URL=./test2.html\">";
print $q->start_html( $title ),
$q->h1( $h1 ),
$q->start_ul;
my $esc = CGI::escape($str);
Encode::from_to($esc, "euc-jp", "utf8" );
my $ua = LWP::UserAgent->new;
$ua->agent('PerlSample/0.1');
$ua->timeout(5);
my $response = $ua->get('http://mimitako.net/api/mecapi.cgi?sentence=' . $esc . '&response=surface,feature');
Encode::from_to($response, "utf8", "euc-jp" );
my @res = split(/<word>/, $response->content);
foreach $i (@res){
$i = decode('utf8', $i);
my @wc = ("名詞", "動詞", "形容詞", "助動詞", "助詞" , "接頭詞" , "接続詞" , "記号" );
my @fn = ("N" , "V" , "A" , "MV" , "JOSHI","SETTOUSHI", "SETSUZOKUSHI", "KIGOU");
for($j=0; $j<@wc; $j++){
if($i =~ /<surface>(.+)<\/surface><feature>$wc[$j]/){
$str = encode('utf8', $1);#utf8
my $filename = encode('euc-jp', $fn[$j]);
open(OUT, ">>./dir/$filename.txt");
Encode::from_to($fn[$j], "utf8", "euc-jp" );
print $fn[$j].$str." ";
$str = encode('euc-jp', $1);
Encode::from_to($str." ", "utf8", "euc-jp" );
print OUT "$str\n";
close(OUT);
last;
}
}
}
}