这就是我试图转换为 python
这是我有点迷路的地方
foreach (@files) {
if ($_ =~ /_histogram/) { next; } #Exclude all the histogram files
for($row = 0, $mytype = 500; $row < $filearray_count; $row++) {
if ($_ eq $filearray[$row][0]) {
$mytype = $filearray[$row][1];
print "$row, $mytype, $_ \n";
break;
}}
$myfile = $mydir.$_;
if ($mytype > 0) {
open($in, "<", ($myfile)) or die "Can't open source file $myfile: $!";
if ($mytype >= 500) { $mytype += ++$new_attribute; }
#print "$row, $mytype, $_ \n";
this while loop is confusing. Is it setting $Instring equal to $in?
while ($inString = <$in>) {
$inString =~ s/^\s*(.*)\s*$/$1/;
if ($inString =~ /Feature File Version:/) { next; }
if ($mytype eq 11 && $inString !~ /Subject:/) { next; }
if ($mytype eq 11 && $inString =~ /Subject:/) {
my($f1, $f2, $f3) = $inString =~ m/(.*\t)(.*\t)(.*)/;
#print $out $inString, "\n";
$f3 =~ s/(\\\d{3})/\^/g;
print $out $mytype, "\t", $f1, $f2, $f3, "\n";
foreach ($f3) {
push @f4, split(/(Subject:|In-Reply-To:|Reply-To:|To:|From:|Bcc:|Cc:|Host:|Date:|Distribution:)/i);
}
#print $out $mytype, "\t", $f1, "\t", "scalar=", $#f4+1, "\n";
$count = 0;
while ($count < $#f4) {
$f4[$count+2] =~ s/\^/ /g;
push @f5, substr(join('', $f4[$count+1], $f4[$count+2]), 0, 50);;
$count = $count + 2;
这部分很容易理解}
print $out $mytype, "\t", $f1, $_, "\t", $f3, "\n" for @f5;
undef @f4;
undef @f5;
next;
}
不确定这里的替换。$inString =~ s/(\\d{3})/\^/g; 打印 $out $mytype, "\t", $inString, "\n";
}
}
};