All pastes #110456 Raw Edit

SkaBob

public text v1 · immutable
·published 2006-08-01 18:09 UTC
rendered paste body
$file = $ARGV[0];
open(CLV_DATA, $file);
@lines =<CLV_DATA>;
close(CLV_DATA);

foreach (@lines) {
        $_ =~ s/\r\n//;
        @this_row = split(/\t/);

        my $these_values;

        for ($x = 0; $x <= $#this_row; $x++) {
                if ($x == $#this_row) {
                        $these_values .= "'".$this_row[$x]."'";
                } else {
                        $these_values .= "'".$this_row[$x]."', ";
                }
        }
        $this_query = qq(INSERT INTO fruits VALUES ($these_values));
        $dbh->prepare($this_query)
                or die "Couldn't prepare query: ".$dbh->errstr;
        $dbh->do($this_query)
                or die "Couldn't execute query: ".$dbh->errstr;
}