Notes:
And here is a sample CSV file you can use with the supplied file, directory, and column names. Save this as foo.csv in the same directory as the script:use DBI; use File::Basename; use strict; my $dir = '.'; my $file = 'foo.csv'; my $table = (fileparse($file,'.csv'))[0]; my $cols = [qw(name id date)]; my $sep = ','; my $dbh = DBI->connect( "DBI:CSV:f_dir=$dir;csv_eol=\n;csv_sep_char=$sep;", {RaiseError=>1}, ); $dbh->{csv_tables}->{$table} = { file => $file, col_names => $cols, }; my $xml = My::DBIx::XML_RDB->new($dbh); $xml->DoSql("select * from $table"); print $xml->GetData(); package My::DBIx::XML_RDB; use base qw(DBIx::XML_RDB); sub Initialise { my ($self,$dbh) = @_; $self->{dbh} = $dbh; $self->{output} = qq|<?xml version="1.0"?>\n<DBI>\n|; return 1; }
string,10,07/13/1970 foo,999999,04/01/1940 bar,0,12/31/1999
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
CSV to XML (the quick and not so dirty way)
by jeffa (Bishop) on Jun 28, 2002 at 22:56 UTC |