LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 767|回复: 1

怎样将一个while中第1个if中的反向引用变量$1的值带进第2个if里?

[复制链接]
发表于 2004-6-12 23:26:22 | 显示全部楼层 |阅读模式
在perl里,怎样将一个while中第1个if中的反向引用变量$1的值带进第2个if里?



#!/usr/bin/perl
open (FILE1,"dataaudit1.log") ||die "fail\n";
open (FILE2,">cem_slot.log") ||die "cem_slot.log don't open\n";
open (FILE3,">cem_pec.log") ||die "cem_pec.log don't open\n";
while (<FILE1>) {
if (/MC800BTS\d{4}\s+1.+(XCEM|CCEM|UNKNOWN)\s+(000PNT|UNKNOWN)/) {
print FILE3 "$_";
$a=$1;
$b=$2;
}
elsif (/MC800BTS\d{4}.+\s+800\s+F/) {
print FILE2 "$_";
print $a;
print $b;}
}
close (FILE1);
close (FILE2);
close (FILE3);
发表于 2004-6-14 02:05:49 | 显示全部楼层

回复: 怎样将一个while中第1个if中的反向引用变量$1的值带进第2个if里?

最初由 blackant 发表
在perl里,怎样将一个while中第1个if中的反向引用变量$1的值带进第2个if里?


#!/usr/bin/perl
open (FILE1,"dataaudit1.log") ||die "fail\n";
open (FILE2,">cem_slot.log") ||die "cem_slot.log don't open\n";
open (FILE3,">cem_pec.log") ||die "cem_pec.log don't open\n";
while (<FILE1>) {
my ($a, $b);
if (/MC800BTS\d{4}\s+1.+(XCEM|CCEM|UNKNOWN)\s+(000PNT|UNKNOWN)/) {
print FILE3 "$_";
$a=$1;
$b=$2;
}
elsif (/MC800BTS\d{4}.+\s+800\s+F/) {
print FILE2 "$_";
print $a;
print $b;}
}
close (FILE1);
close (FILE2);
close (FILE3);
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表