真正的程序员都是尽量偷懒的,能少些一个字不愿多写一个,最烦的是打字速度低于思考速度。在简洁方面,PERL还是比PHP强多了。这个DISCUZ日志同步到论坛与微博的功能用PERL大概400行代码就搞定了。下面是部分代码
sub sync_blogs_to_forum {
my ($bids, $fid, $mic, $pend, $ipover) = @_;
for my $bid(@$bids) {
next if not $bid;
my ($s, $c, $cs, $post, $uid, $ip) = get_post_from_blog($bid);
if ($CFG{gtest} && $c) {
print "Content $post <br>" ;
next;
}
my $bsrc ="blog:$bid";
my $destloc ='';
my $rec=undef;
eval {
my $tid=0;
if($fid >0) {
$destloc = "forum:$fid";
$rec = check_sync_status($bsrc, $destloc);
if(not ref($rec)) {
$tid = add_post($fid, $s, $post, $uid, $ipover||$ip);
set_sync_status($bsrc, $destloc, $tid) if $tid;
}else {
$tid = $rec->[0];
}
print qq!Added <a href="/forum.php?mod=viewthread\&tid=$tid">$s</a><p>! if $tid;
}else {
#print "No sync forum<p>";
}
if($mic) {
$destloc = "mblog";
$rec = check_sync_status($bsrc, $destloc);
my $mid;
my $msg = substr($cs, 0, 128);
$msg .= qq! -- <a href="/blog-$uid-$bid.html">$s</a>!;
if((not ref($rec)) || (time()-$rec->[1])>24*3600) {
$mid = add_microblog($msg, $uid, $ipover||$ip);
set_sync_status($bsrc, $destloc, $mid) if $mid;
}else {
$mid = $rec->[0];
}
print "$msg<p>Posted MID=$mid <br>" if $mid;
}else {
#print "No sync mic<p>";
}
};
if($@) {
print "Error: $@<br>" ;
}
}
}