本人不懂perl,现在有一个用perl操作文件的问题请教高手,是修改文件里面指定的位置的数据,因为修改的文件太大,不能贴出来,现在把源代码贴出来
如果哪位大哥看懂了这个程序,可以帮助我的请顶贴留下电话或者QQ号码,我散分,并适当金钱感谢.
use POSIX;
my ($fh)=0;
if (@ARGV < 1)
{
die("Usage: perl cell.pl filename\n");
}
$fn = $ARGV[0];
if (!open($fh,$fn))
{
die ("cannot open data file\n");
}
@line=<$fh>;
$line_num=@line;
#print $line_num;
$j=0;
$delta = 500;
for ($i=0;$i<$line_num;$i++)
{
#chop(@line[$i]);
if(@line[$i] =~ /ECP LCNTS/)
{
$ELCNT_start=$i;
}
if(@line[$i] =~ /ECP VSCNTS-8K/)
{
$ELCNT_stop=$i;
}
if(@line[$i] =~ /$CL[0-9][0-9][0-9] F/)
{
$j++;
@cell_pos[$j]=$i;
#print "@line[$i].......$i\n";
}
if(@line[$i] =~ /IMS /)
{
$j++;
@cell_pos[$j]=$i;
last;
}
}
$cell_num=@cell_pos-1;
$carr_num=0;
$drop_num=0;
$drop1_num=0;
$droptemp=55+int(rand(10));
#print "$cell_num\n";
for ($i=1;$i<$cell_num;$i++)
{
if (@line[@cell_pos[$i]+3] =~ /Both Data Links Out-Of-Service/)
{
next;
}
#print "$i....@cell_pos[$i]\n";
for ($j=@cell_pos[$i];$j<@cell_pos[$i+1];$j++)
{
if((@line[$j] =~ /CDMA-PAF-CARR/) && (@line[$j] !~ /CDMA-PAF-CARR-/))
{
#print "$j\n";
$PCARR_start=$j;
}
if(@line[$j] =~ /CDMA-PAF-CARR-L/)
{
#print ".....$j\n";
$PCARR_stop=$j;
}
if(@line[$j] =~ /CDMA-PAF-CARR-SC/)
{
$PCARRSC_start=$j;
#print "$PCARRSC_start......";
}
if(@line[$j] =~ /CDMA-PAF-CARR-RC/)
{
$PCARRSC_stop=$j;
#print "$PCARRSC_stop\n";
#last;
}
if(@line[$j] =~ /ECP-PAF-CARR-SC/)
{
$EPCARRSC_start=$j;
}
if(@line[$j] =~ /MPCG-LAF AMPS/)
{
$EPCARRSC_stop=$j;
last;
}
}
$sect=0;
for($j=$PCARRSC_start;$j<$PCARRSC_stop;$j++)
{
if(@line[$j] =~ /SECT [0-9][0-9]/)
{
$sect++;
}
if(@line[$j] =~ /EVRC/)
{
#print "@line[$j]\n";
@temp = split(/ +/,@line[$j+1]); #line 2
$pcarrsc17v=@temp[6];
$pcarrsc18v=@temp[7];
@temp = split(/ +/,@line[$j+3]); #line 4
$pcarrsc40v=@temp[7];
$pcarrsc41v=@temp[8];
$drop = $drop+$pcarrsc17v+$pcarrsc18v+$pcarrsc40v+$pcarrsc41v;
$carr_num=$carr_num+1;
if(($pcarrsc17v+$pcarrsc18v+$pcarrsc40v+$pcarrsc41v)==1)
{
$drop1_num=$drop1_num+1;
if($drop_num+$drop1_num<$droptemp)
{
}
else
{
@line[$j+1]=sprintf ("%s%s %s",substr(@line[$j+1],0,40),"00000 00000",substr(@line[$j+1],52,length(@line[$j+1])-52));
@line[$j+3]=sprintf ("%s%s %s",substr(@line[$j+3],0,46),"00000 00000",substr(@line[$j+3],58,length(@line[$j+3])-58));
}
}
if(($pcarrsc17v+$pcarrsc18v+$pcarrsc40v+$pcarrsc41v)>1)
{
$drop_num=$drop_num+1;
if($drop_num+$drop1_num<$droptemp)
{
@line[$j+1]=sprintf ("%s%s %s",substr(@line[$j+1],0,40),"00001 00000",substr(@line[$j+1],52,length(@line[$j+1])-52));
@line[$j+3]=sprintf ("%s%s %s",substr(@line[$j+3],0,46),"00000 00000",substr(@line[$j+3],58,length(@line[$j+3])-58));
}
else
{
@line[$j+1]=sprintf ("%s%s %s",substr(@line[$j+1],0,40),"00000 00000",substr(@line[$j+1],52,length(@line[$j+1])-52));
@line[$j+3]=sprintf ("%s%s %s",substr(@line[$j+3],0,46),"00000 00000",substr(@line[$j+3],58,length(@line[$j+3])-58));
}
}
}
}
}
#print $carr_num,"\n";
#print $drop1_num,"\n";
#print $drop_num,"\n";
#printf("%f\n", $call_ass/$call_try);
#print $drop;
for($i=0;$i<$line_num;$i++)
{
print @line[$i];
}
[解决办法]
打开文件,读取,模式匹配,输出,具体有些我也看不懂。。。
[解决办法]
代码太长了
:-)
[解决办法]
use POSIX;my ($fh)=0;if (@ARGV < 1){die("Usage: perl cell.pl filename\n");}$fn = $ARGV[0];if (!open($fh,$fn)) {die ("cannot open data file\n");}@line=<$fh>;$line_num=@line;#print $line_num;$j=0;$delta = 500;for ($i=0;$i<$line_num;$i++){#chop(@line[$i]);if(@line[$i] =~ /ECP LCNTS/){$ELCNT_start=$i;}if(@line[$i] =~ /ECP VSCNTS-8K/){$ELCNT_stop=$i;}if(@line[$i] =~ /$CL[0-9][0-9][0-9] F/){$j++;@cell_pos[$j]=$i;#print "@line[$i].......$i\n";}if(@line[$i] =~ /IMS /){$j++;@cell_pos[$j]=$i;last;}}$cell_num=@cell_pos-1;$carr_num=0;$drop_num=0;$drop1_num=0;$droptemp=55+int(rand(10));#print "$cell_num\n";for ($i=1;$i<$cell_num;$i++){if (@line[@cell_pos[$i]+3] =~ /Both Data Links Out-Of-Service/){next;}#print "$i....@cell_pos[$i]\n";for ($j=@cell_pos[$i];$j<@cell_pos[$i+1];$j++){if((@line[$j] =~ /CDMA-PAF-CARR/) && (@line[$j] !~ /CDMA-PAF-CARR-/)){#print "$j\n";$PCARR_start=$j; }if(@line[$j] =~ /CDMA-PAF-CARR-L/){#print ".....$j\n";$PCARR_stop=$j;}if(@line[$j] =~ /CDMA-PAF-CARR-SC/){$PCARRSC_start=$j;#print "$PCARRSC_start......"; }if(@line[$j] =~ /CDMA-PAF-CARR-RC/){$PCARRSC_stop=$j;#print "$PCARRSC_stop\n";#last;}if(@line[$j] =~ /ECP-PAF-CARR-SC/){$EPCARRSC_start=$j;}if(@line[$j] =~ /MPCG-LAF AMPS/){$EPCARRSC_stop=$j;last;}}$sect=0;for($j=$PCARRSC_start;$j<$PCARRSC_stop;$j++){if(@line[$j] =~ /SECT [0-9][0-9]/){$sect++;}if(@line[$j] =~ /EVRC/){#print "@line[$j]\n";@temp = split(/ +/,@line[$j+1]); #line 2$pcarrsc17v=@temp[6];$pcarrsc18v=@temp[7];@temp = split(/ +/,@line[$j+3]); #line 4$pcarrsc40v=@temp[7];$pcarrsc41v=@temp[8];$drop = $drop+$pcarrsc17v+$pcarrsc18v+$pcarrsc40v+$pcarrsc41v;$carr_num=$carr_num+1;if(($pcarrsc17v+$pcarrsc18v+$pcarrsc40v+$pcarrsc41v)==1){ $drop1_num=$drop1_num+1;if($drop_num+$drop1_num<$droptemp){}else{@line[$j+1]=sprintf ("%s%s %s",substr(@line[$j+1],0,40),"00000 00000",substr(@line[$j+1],52,length(@line[$j+1])-52));@line[$j+3]=sprintf ("%s%s %s",substr(@line[$j+3],0,46),"00000 00000",substr(@line[$j+3],58,length(@line[$j+3])-58));}}if(($pcarrsc17v+$pcarrsc18v+$pcarrsc40v+$pcarrsc41v)>1){$drop_num=$drop_num+1;if($drop_num+$drop1_num<$droptemp){@line[$j+1]=sprintf ("%s%s %s",substr(@line[$j+1],0,40),"00001 00000",substr(@line[$j+1],52,length(@line[$j+1])-52));@line[$j+3]=sprintf ("%s%s %s",substr(@line[$j+3],0,46),"00000 00000",substr(@line[$j+3],58,length(@line[$j+3])-58));}else{@line[$j+1]=sprintf ("%s%s %s",substr(@line[$j+1],0,40),"00000 00000",substr(@line[$j+1],52,length(@line[$j+1])-52));@line[$j+3]=sprintf ("%s%s %s",substr(@line[$j+3],0,46),"00000 00000",substr(@line[$j+3],58,length(@line[$j+3])-58));}}}}}#print $carr_num,"\n";#print $drop1_num,"\n";#print $drop_num,"\n";#printf("%f\n", $call_ass/$call_try);#print $drop;for($i=0;$i<$line_num;$i++){print @line[$i];}
[解决办法]
perl语言的可读性是差,python的可读性好。
------解决方案--------------------
没注释,没源数据片段,我想很少会有人能够帮到你吧。
[解决办法]
MaxWit技术讨论区http://linux.chinaunix.net/bbs/forum-70-1.html
[解决办法]
放在你的整个环境里面去琢磨。会有结果的。
[解决办法]
看来是很难!