Skip to content

Instantly share code, notes, and snippets.

@okamuuu
Last active October 22, 2016 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okamuuu/22f894b33021861f4fcf3629768737d9 to your computer and use it in GitHub Desktop.
Save okamuuu/22f894b33021861f4fcf3629768737d9 to your computer and use it in GitHub Desktop.
use Encode qw/encode_utf8 decode_utf8/;
use DBIx::Sunny;
use Data::Dumper;

sub dbh {
    my ($self) = @_; 
    return $self->{dbh} //= DBIx::Sunny->connect('dbi:mysql:db=isuda', 'root', '', {
        Callbacks => {
            connected => sub {
                my $dbh = shift;
                $dbh->do(q[SET SESSION sql_mode='TRADITIONAL,NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY']);
                $dbh->do('SET NAMES utf8mb4');
                return;
            },  
        },  
    }); 
}

my $entries = dbh()->select_all(q[SELECT keyword FROM entry]);
my @keywords = map { $_->{keyword} } @$entries;

my $count_of = {}; 
for my $k (@keywords) {
  $count_of->{$_}++ for split('', $k);
}

for ( sort { $count_of->{$a} <=> $count_of->{$b} } keys $count_of ){
  print $_, ':', $count_of->{$_}, "\n";
}

上位3つ

Wide character in print at count.pl line 31.
ン:1055
Wide character in print at count.pl line 31.
年:1162
Wide character in print at count.pl line 31.
ー:1272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment