Gustav
Code: Select all
#!/opt/local/bin/perl
#Copyright 2010 by Gustav von Roth, Gmail2AdaSIM[at]vonroth.com
#
#This software is free software; you can redistribute it and/or modify
#it under the same terms as Perl itself.
use strict;
use warnings;
use lib '.';
use Text::CSV_PP;
if(($#ARGV+1) != 2) {
print "Gmail2AdaSIM.pl <infile.csv> <outfile.txt>\n\n";
print
"\n".
"example usage:"."\n".
"perl Gmail2AdaSIM.pl google.csv gmail2AdaSim.csv"."\n"
;
exit;
}
my $inFile = $ARGV[0];
my $outFile = $ARGV[1];
#open input file
open my $gmail_csv_fh, "<:encoding(UTF-16)", $inFile or die "$inFile: $!";
my $gmail_csv = Text::CSV_PP->new({ binary => 1});
my $status = $gmail_csv->getline ($gmail_csv_fh);
my @headerNames = $gmail_csv->fields();
$gmail_csv->column_names (@headerNames);
open my $AdaSim_csv_fh, ">", $outFile or die "$outFile: $!";
#print header
print $AdaSim_csv_fh "# Gmail2AdaSIM\n";
print $AdaSim_csv_fh "# \"Name\", Number\n";
my $memNumber=1;
while (my $hr = $gmail_csv->getline_hr ($gmail_csv_fh))
{
my $mobileNum;
for(my $i=1;$i< @headerNames;$i++)
{
#print $allKeys[$i] . "\n";
if($hr->{$headerNames[$i]} eq "Mobile")
{
$hr->{$headerNames[$i+1]} =~ s/[\(|\)|-]//g ;
$hr->{$headerNames[$i+1]} =~ s/-/ /g ;
my($mobileNum ) = $hr->{$headerNames[$i+1]} =~ m/^([\+|\d|\s]*)/ ;
print $hr->{$headerNames[0]} .":". $mobileNum . "\n";
print $AdaSim_csv_fh "\"" . substr($hr->{$headerNames[0]},0,17) ."\"," . substr($mobileNum,0,19) . "\n";
$i = @headerNames + 1;
}
}
$memNumber++;
} #while
$memNumber--;
print "Conversion complete!.\n Converted $memNumber line(s);\n Output in file: $outFile\n";