in reply to CSV to XML (the quick and dirty way)
Much better, but i still enjoy a little OO hacking now and then. :Duse strict; use DBI; use File::Basename; use XML::Generator::DBI; use XML::Handler::YAWriter; 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 $ya = XML::Handler::YAWriter->new(AsFile => "-"); my $generator = XML::Generator::DBI->new( Handler => $ya, dbh => $dbh, Indent => 1, ); $generator->execute("select * from $table");
UPDATE:
Silly /me - XML::CSV:
perl -MXML::CSV -e '$o=XML::CSV->new;$o->parse_doc(shift,{headings=>sh +ift});$o->print_xml' no_headings.csv perl -MXML::CSV -e '$o=XML::CSV->new;$o->parse_doc(shift,{headings=>sh +ift});$o->print_xml' headings.csv 1
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)
|
|---|