#!/bin/perl

use DBI;
#
open (FILE, "<$ARGV[0]") or die("Can't open $ARGV[0]");

@LINES = <FILE>;

close(FILE);

my $connection = DBI->connect("DBI:mysql:smartdb:localhost", "admin", "1234567890", {RaiseError => 0, PrintError => 0, mysql_enable_utf8 => 1});

foreach $line(@LINES) {
    @tokens = split(" ", $line);
    $char = substr($tokens[0], 0, 1);
    $command = "insert into ppword (word, past_tense, pp_tense, category, chinese) values ('$tokens[0]', '$tokens[1]', '$tokens[2]', '$char', '$tokens[3]')";
    print "$command\n";
    $query = $connection->prepare($command);
    $query->execute();
}
