I'm working on migrating from MDaemon to Google Apps. As part of this process I'm exporting the contacts and calendars for all of our users into CSV files then reading them into a perl script and importing them into Google Apps.
Here's a sample calendar export shown in vi with ":set list" on.
"Event 1","05/05/2009","0:00:00","05
/05/2009","23:59:00","True","True","05/04/2009","23:45:00",,,,"",,,"False","Normal",0$
"Event 2","09/21/2009","11:00:00","09/21/2009","11:30:00","False","False",,,"email@TELUS.COM","",,"Notes from=A0^M$
Vendor=A0",,"","False","Normal",1$
"Event 3","04/05/2010","0:00:00","04/05/2010","23:59:00","True","True","04/04/2010","23:45:00",,,,"",,,"False","Normal",0$
"Event 4","05/05/2010","0:00:00","05/05/2010","23:59:00","True","True","05/04/2010","23:45:00",,,,"",,,"False","Normal",0$
I'm running into trouble with the lines ending in ^M$ which are supposed to be embedded line endings. My CSV parser Text::CSV_XS is parsing them as multiple lines rather than a single line. How can I replace the ^M$ with ^M? Any other suggestions are welcome.
Here's my parsing code:
my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/,auto_diag => 1 }) or
die "Cannot use CSV: ".Text::CSV_XS->error_diag ();
open my $fh, "<", $username . "-calendar.csv" or die $!;
while (my $row = $csv->getline ($fh)) {
print STDERR "NEW LINE: " . Dumper($row) . "END NEW LINE\n";
push @rows, $row;
}
$csv->eof or $csv->error_diag ();
close $fh;
UPDATE 1: Here's the output from "file" regarding this file:
Non-ISO extended-ASCII English text, with very long lines, with CRLF, LF line terminators