----------------------------------------下面是程序
###############################################
#! /usr/bin/perl
## "try_breakline"
##joneykk
######
####invoke method:try_breakline filename
####The filename is consisted of Chinese or English characters.The encoding should be utf-8.
use Encode;
$linewidth=75;
$tri_bi=2;
my $path=$ENV{'PWD'};
$name=$path."//".$ARGV[0];
open NEWF,">".$name.".klg" or die "can't open file";
while (<>)
{
my $line = $_;
while ($line =~/./)
{
$num = 0;
$line2 = $line;
$x=0;
$buf=0;
while ($line2 =~/./)
{
#####This flag is to mark:there are only character <$linewidth=75,to avoid this part to be lost.
$flag=0;
$buf++;
$line2 = $';
if(ord($&)>=128)
{
$x++;
if($x==$tri_bi)
{
$num+=2;
$x=0;
}
}
else
{
$num++;
}
##################################
if($num>=$linewidth && $x==0)
{
$flag=1;
##########################
###If there is a word in the wrap position, the wrap should be avoid.
$char=substr($line,$buf-1,1);
if($char =~/[a-zA-Z0-9]/)
{
while(substr($line,$buf-1,1)=~/[a-zA-Z0-9]/)
{
$buf--;
$num--;
}
}
sub getsignlength
{
##the reture value is the length from the beginnig to the sign(included)
my $string=$_[0];
my $len=0;
while($string =~/,|。|、|?/)
{
$len+=length($`.$&);
$string=$';
}
return $len;
}