By the way, here is the perl code I wrote:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $file = shift or
die "Usage: $0 csvfile\nStopped";
my $csv = Text::CSV->new ( { binary => 1 } );
open (CSV, "<", $file) or die $!;
sub print_mpl {
local $\ = "\r\n";
print @_;
}
print_mpl '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
print_mpl '<MPL Version="2.0" Title="Created from ', $0, '">';
my @fieldnames;
while (<CSV>) {
if ($csv->parse($_)) {
if ($. == 1) {
@fieldnames = $csv->fields();
for (@fieldnames) {
$_ = 'Filename' if $_ eq 'Web Media URL';
}
}
else {
my @cells = $csv->fields();
print_item(\@cells, \@fieldnames);
}
} else {
my $error = $csv->error_input;
print "CVS row parse error: $error";
}
}
close CSV;
print_mpl '</MPL>';
sub print_item {
my ($cellsref, $namesref) = @_;
print_mpl '<Item>';
for (my $i = 0; $i < @$namesref; $i++) {
unless ($cellsref->[$i] eq '' or $cellsref->[$i] eq '-') {
$cellsref->[$i] =~ s/\&/&/g;
$cellsref->[$i] =~ s/</</g;
$cellsref->[$i] =~ s/>/>/g;
print_mpl '<Field Name="', $namesref->[$i], '">', $cellsref->[$i], '</Field>'
}
}
print_mpl '<Field Name="Media Type">Audio</Field>';
print_mpl '</Item>';
}