Listing 1 CSV2db::Filemaker
package CSV2db::Filemaker;
use strict;
use vars qw($VERSION);
use Date::Parse;
use Carp;
$VERSION = substr q$Revision: 1.0 $, 10;
# Filemaker exports newlines embedded in fields as ^K characters, so
# turn them back into newlines.
sub embeddednewlines2nl {
my $s = shift @_;
$s =~ tr/\013/\n/;
$s;
}
# Filemaker multiple-checkboxes are exported as ^K-separated lists,
# but we need to feed them to MySQL as comma-separated. This does the fix.
sub embeddednewlines2comma {
my $s = shift @_;
$s =~ s/,//g; # Sorry, have to strip internal commas
$s =~ s/\013/,/g;
$s;
}
# Change Filemaker exported dates to MySQL-acceptable ones. Actually,
# this routine should work across a range of input date formats.
sub date2sql {
my $s = shift @_;
$s =~ s/^\s*//;
$s =~ s/\s*$//;
my($yyyy, $mm, $dd) = (localtime(str2time($s)))[5,4,3] if $s;
if (defined $yyyy && defined $mm && defined $dd) {
$s = sprintf "%04d-%02d-%02d", $yyyy + 1900, $mm + 1, $dd;
}
$s;
}
# Change "hh:mm:ss AM"-style times to 24-hour hh:mm:ss format
sub time2sql {
my $s = shift @_;
$s =~ s/^\s*//;
$s =~ s/\s*$//;
my($hh, $mm, $ss, $ap) = $s =~ /(\d+):(\d+):(\d+)\s+(\S+)/;
if (defined $hh && defined $mm && defined $ss && defined $ap) {
$hh += 12 if $ap =~ /pm/i;
$s = "$hh:$mm:$ss";
}
$s;
}
1;
|