WWW::Mechanize とりあえず完成!

use strict;
use warnings;

use WWW::Mechanize;
use HTML::TreeBuilder;
use utf8;
use Encode;
binmode STDOUT, ':utf8';

sub say {print @_, "\n";}


open(IN, '<:encoding(utf8)', 'word_list.txt');
open(OUT, ">word_list_output.txt");

while(<IN>){
    chomp;
    my ($word) = split(/,/, $_); #split リストコンテキストにしないと文字列として認識してくれない
    
    
    

my $mech = WWW::Mechanize->new();
   $mech->agent_alias( 'Windows IE 6' );


   $mech->get('http://eow.alc.co.jp/serch');

print $word."\n\n";


# 検索フォームに単語を入力してサブミット
$mech->submit_form(
    fields      => {
        q => "$word",
    }
) or die 'submitting failed';

my $res = $mech->content;


my $tree = HTML::TreeBuilder->new;
   $tree->parse($res);

   $tree->look_down('class', 'wordclass');
my @items =$tree->find('tag', 'ol');

my $input_wd = encode('utf8',$items[0]->as_text); #外から入ってきたものを変換してperl内部で処理する
                                                  #処理はprintやsplitなどを指す



print OUT $word."\t";
print OUT $input_wd."\n";


$tree->delete;
};

	
close(IN);
close(OUT);