- 论坛徽章:
- 0
|
刚学了3个星期的perl,希望能帮到你
#!perl -w
use strict;
my $fh;
my $num;
open $fh,'<','WH.A0.txt' or die "Can't open the file!!!\n";
while ( my $line = readline $fh ){
chomp $line;
my @parts = split /\./, $line;
next if( $line =~ m/ ^ .*? (M72|G93X0Y0) .*? $ /mgx);
if ( my ($a1 , $a2) = $line =~ m/ ^ T \d{2} C (\d*) . (\d+) $ /xg ){
print "Before ==> ", $line, "\n";
if ( $a2 eq '0020' )
{ $line =~ s/$parts[0].$parts[1]/$parts[0]3.2/mgx; }
if ( $a1 && ( $a1 ge 8 || $a1 lt 20)){
$num = $a1;
$num = $num - 8;
my $sub = substr ($parts[0],0,4);
$line =~ s/$parts[0].$parts[1]/$sub$num.$parts[1]/gx;
}
if ( $a1 eq 20 ){
my $sub1 = substr ($parts[0],0,4);
my $zero = 0;
$line =~ s/$parts[0].$parts[1]/$sub1$zero.$parts[1]/gx;
}
}
$line =~ s/0+$/0/gmx;
print "Result => ", $line, "\n\n";
}
__END__
M48
T01C.0020
T02C.4000
T03C3.1950
T04C8.7000
T05C9.1000
T06C20.0000
%
M72
G93X0Y0
T01
X017054Y007558
Y008176
结果输出如下, 输出格式可以改成自己想要的,下面的输出可以把转换结果看得清晰些:
Result => M48
Before ==> T01C.0020
Result => T01C3.2
Before ==> T02C.4000
Result => T02C.40
Before ==> T03C3.1950
Result => T03C3.1950
Before ==> T04C8.7000
Result => T04C0.70
Before ==> T05C9.1000
Result => T05C1.10
Before ==> T06C20.0000
Result => T06C0.0
Result => %
Result => T01
Result => X017054Y007558
Result => Y008176 |
|