% my $dbi = app->dbi; my $op = param('op') // ''; my $book_id = param('book-id'); my $show_word_count; my $word_count_h = {}; my $word = param('word'); my $word_length = length $word; if ($word_length) { $show_word_count = 1; for (my $i = 0; $i < 66; $i++) { my $num = sprintf "%02d", $i + 1; my $content = $dbi->select( 'content_no_tag', table => 'book', where => {id => $num} )->value; my $content_length = length $content; $content =~ s/$word//g; my $content_length_no_word = length $content; my $word_count = ($content_length - $content_length_no_word) / $word_length; $word_count_h->{$num} = $word_count; } } warn dumper $word_count_h; my $books = $dbi->model('book')->select(['id', 'short_name'])->all; my $content; if ($book_id) { $content = $dbi->model('book')->select( 'content', where => {id => $book_id} )->value; } %> % layout 'common';
書 | % if ($word_length) { 回数 % } |
{id}" %>" href="<%= url_for->query('book-id' => $book->{id}) %>"><%= $book->{short_name} %> | <%= $word_count_h->{$book->{id}} %> |