in reply to A TRUE-once variable
I know this isn't too subtle, but I find I can look at it and know what it does.my $do = 1; for (0...9) { stuff_to_do_always(); if ($do) { stuff_to_do_first_time(); } else { stuff_to_do_other_times(); } $do = 0; }
use DBI; my $dbh = DBI->connect("DBI:mysql:database=chess", "usr", "pwd"); # o +r whatever my @line; my $sth; while (<DATA>) { # your parsing: chomp; next if /^\s*$/; @line = split /;/; # these lines deal with the only variation in # your data I can see - there may be others: if (@line == 3) { push @line, $line[2]; $line[2] = 'NULL'; } # and finally, DBI takes the strain: $sth = $dbh->prepare("INSERT INTO eco_class (eco_id,eco,opening,va +riation,moves) VALUES (NULL,?,?,?,?)") or die $dbh->errstr; $sth->execute(@line) or die $dbh->errstr; }
|
---|