vcf_generator.pl

use URI::Escape;
use Encode;
sub qp_encode{
my ($str) = @_;
$strU= encode('utf8',decode('gbk',$str));
$strUri = uri_escape($strU);
$strUri =~ s/%/=/g;
return $strUri;
}
$usage = '
Usage:
perl vcf_generator.pl your_txl
P.S. your_txl format should be like below:
Name Mobile Tel ORG Category
For Example:
XCY 180****4365 - 网运部 临沂电信
';
if($#ARGV < 0){
print $usage;
exit;
}
open RH,$ARGV[0];
@lns = <RH>; chomp @lns;
close RH;
for($i = 0; $i < @lns; $i ++){
@t = split(/\t/,$lns[$i]);
$fname = &qp_encode(substr($t[0],0,3));
$lname = &qp_encode(substr($t[0],2));
$name = &qp_encode($t[0]);
$mobile = $t[1];
$tel = $t[2];
if($tel !~ /-/){ $tel = "0539$tel";}
$org = &qp_encode($t[3]);
$category = &qp_encode($t[4]);
$tpl = "BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:$fname;$lname;;;
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:$name
TEL;CELL;PREF:$mobile
TEL;WORK:$tel
ORG;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:$org
CATEGORIES;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:$category
END:VCARD";
print $tpl . "\n";
}

 

你可能感兴趣的:(perl,generator,PL,vcf)