biblesearch / tmp / count_word.pl /
Newer Older
35 lines | 0.669kb
improve design
Yuki Kimoto authored on 2014-03-27
1
use strict;
2
use warnings;
3
use utf8;
4
use DBIx::Custom;
5

            
6
my $word ='主';
7
my $word_length = length $word;
8
my $word_q = quotemeta($word);
9

            
10
my $dbi = DBIx::Custom->connect(
11
  dsn => "dbi:SQLite:dbname=../db/bible.db",
12
  option => {sqlite_unicode => 1}
13
);
14

            
15
for (my $i = 0; $i < 66; $i++) {
16
  my $num = sprintf "%02d", $i + 1;
17
  
18
  my $content = $dbi->select(
19
    'content_no_tag',
20
    table => 'book',
21
    where => {id => $num}
22
  )->value;
23

            
24
  my $content_length = length $content;
25

            
26
  $content =~ s/$word//g;
27

            
28
  my $content_length_no_word = length $content;
29

            
30
  my $word_count = ($content_length - $content_length_no_word) / $word_length;
31

            
32
  print "$num:$word_count\n";
33
}
34

            
35
1;