Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Creating Table and Inserting Data from CSV

by sk (Curate)
on Oct 04, 2005 at 20:06 UTC ( #497380=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Creating Table and Inserting Data from CSV
in thread Creating Table and Inserting Data from CSV

will regular split not work for this file? If it will then you can try something like this -

#!/usr/bin/perl -w use strict; use DBI; my $line = "var1, var2, var3"; my $dbh = DBI->connect('DBI:mysql:test') or die "Couldn't connect to d +atabase: " . DBI->errstr; my $create = "create table dummy3 (" . join (',', map { $_ . ' varchar +(255) ' } split /,/, $line) . ");"; my $sth = $dbh->prepare($create) or die "Couldn't prepare statement: " + . $dbh->errstr; $sth->execute or die "Couldn't execute statement: " . $sth->errstr;;
mysql> desc dummy3 -> ; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | var1 | varchar(255) | YES | | NULL | | | var2 | varchar(255) | YES | | NULL | | | var3 | varchar(255) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)


Comment on Re^3: Creating Table and Inserting Data from CSV
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://497380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-09-21 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls