cmd.line.geek has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use DBI; use strict; use warnings; # Declare varaibles my $DBNAME = "Test"; my $DBTABLE = "Pandora"; my $DBUSER = "slacker"; my $DBPASS = "password"; my $DBHOST = "localhost"; my $csvfile = "/tmp/nowplayingtest.csv"; # Connect to database at hand, or die my $dbh = DBI->connect("DBI:mysql:$DBNAME:$DBHOST", $DBUSER, $DBPASS); open (INFILE, "/tmp/nowplayingtest.csv") or die "Can't open file!"; while (<INFILE>) { my @rows = split(';', $_); my $artist = $rows[0]; my $title = $rows[1]; my $album = $rows[2]; $dbh->do(qq/insert into "$DBTABLE" (Artist, Title, Album) values ($ +artist, $title, $album/) or warn "failed to insert $artist, $title, $ +album into table - $dbh->errstr" if ($@); my $res = $dbh->selectall_arrayref( q( SELECT Artist, Title, Album FRO +M Pandora)); foreach( @$res ) { print "\n$_->[0], $_->[1] $_->[2] $_->[3]\n\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of uninitialized value...
by wind (Priest) on Feb 08, 2011 at 02:05 UTC | |
by cmd.line.geek (Initiate) on Feb 08, 2011 at 02:09 UTC | |
|
Re: Use of uninitialized value...
by Anonymous Monk on Feb 08, 2011 at 02:10 UTC | |
by Anonymous Monk on Feb 08, 2011 at 02:12 UTC | |
by ikegami (Patriarch) on Feb 08, 2011 at 02:18 UTC | |
by cmd.line.geek (Initiate) on Feb 08, 2011 at 02:23 UTC | |
|
Re: Use of uninitialized value...
by wind (Priest) on Feb 08, 2011 at 18:32 UTC |