gogoglou has asked for the wisdom of the Perl Monks concerning the following question:
Dear perl monks, I have a questions which might be easy, but I am really stuck. I have the following script"
#!/usr/bin/perl use DBI; use Data::Dumper; use strict; use warnings; use CGI; my $fields; my $q= CGI->new(); # Connect to the database my $dbh = DBI->connect('DBI:mysql:mirnas', 'root', 'pass') or die "Couldn't open database: $DBI::errstr; stopped"; my $filename = $ARGV[0]; my $table_name = $ARGV[1]; open(INPUT, $filename); #getting the column names from the text file my $line = <INPUT>; chomp($line); my @fields = split('\t', $line); foreach $fields(@fields){ print "$fields\n"; } $sth = $dbh->prepare("create table $tablename ); $sth->execute;
What I want to do is to create a table where all the columnn names will be the ones stored in fields. I was thinking of using a loop structure where foreach $field it would add a column, but I am not sure if this is thebest way to do that. any suggestions would be really usefull, thank you in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI question
by kennethk (Abbot) on Jun 22, 2010 at 15:01 UTC | |
|
Re: DBI question
by Tux (Canon) on Jun 22, 2010 at 15:07 UTC | |
by gogoglou (Beadle) on Jun 23, 2010 at 11:17 UTC | |
by Tux (Canon) on Jun 23, 2010 at 13:48 UTC | |
by kennethk (Abbot) on Jun 23, 2010 at 13:59 UTC | |
by gogoglou (Beadle) on Jun 24, 2010 at 07:46 UTC | |
by Tux (Canon) on Jun 24, 2010 at 09:53 UTC |