#!/usr/bin/perl
use Digest::MD5 qw(md5 md5_hex md5_base64);
use DBI;

my $dbh = DBI->connect('DBI:mysql:rainbow','root','') || die "Connexion a la base impossible! $DBI::errstr";

open(FILE, 'words.txt') || die('Could not open file');
while(<FILE>) {
  my $data;
  chomp ($data = $_);
  $data =~ s/\r\n?//g;
  $hash = md5_hex $data;
  $data =~ s/'/''/g;
  my @vals = ($data, $hash);
  my $sth = $dbh->prepare("INSERT INTO hash (hash_word,hash_hash) VALUES (?,?)");
  $sth->execute(@vals) || die "Echec insertion! $DBI::errstr";
}
close(FILE);
$dbh->disconnect();
