- 论坛徽章:
- 0
|
文件处理问题
#!/usr/bin/perl
# This Perl srcipt writen by forrest.w
$filename1="file1";
$filename2="file2";
open (FL1,$filename1) or die "cannot open for $! \n";
open (FL2,$filename2) or die "cannot open for $! \n";
@line1=<FL1>;;
@line2=<FL2>;;
@value1=();
@value2=();
@value3=();
$i=0;
foreach (@line1) {
$_=~/(\w+\s+)(\d+\s+)(\d+\.\d+)/;
$j=0;
$value1[$i][$j]=$1;
$value1[$i][$j+1]=$2;
$value1[$i][$j+2]=$3;
$i++;
}
$a=0;
foreach (@line2) {
$_=~/(\d+\s+)(\d+\s+)(\w+\s+)(\w+\d+\s+)(\S+\s+|\w+\s+)(\d+\.\d+)/;
$b=0;
$value2[$a][$b]=$1;
$value2[$a][$b+1]=$2;
$value2[$a][$b+2]=$3;
$value2[$a][$b+3]=$4;
$value2[$a][$b+4]=$5;
$value2[$a][$b+5]=$6;
$a++;
}
print "a=$a \t i=$i \n";
for ($m=0;$m<=$a ;$m++) {
for ($n=0;$n<=$i ;$n++) {
if (($value2[$m][2]==$value1[$n][0]) && (substr ($value2[$m][3],2,4)==$value1[$n][1])&& ($value2[$m][5]==$value1[$n][2]) ) {
print "$value2[$m][0] $value2[$m][1] $value2[$m][2] $value2[$m][3] $value2[$m][4] $value2[$m][5] \n" ;
# can write to your file.
}
}
}
close FL1;
close FL2; |
|