biblesearch / tmp / count_word.pl /
Yuki Kimoto improve design
dc331a8 10 years ago
1 contributor
35 lines | 0.669kb
use strict;
use warnings;
use utf8;
use DBIx::Custom;

my $word ='主';
my $word_length = length $word;
my $word_q = quotemeta($word);

my $dbi = DBIx::Custom->connect(
  dsn => "dbi:SQLite:dbname=../db/bible.db",
  option => {sqlite_unicode => 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;

  print "$num:$word_count\n";
}

1;