作业帮 > 综合 > 作业

关于perl的问题现有a文件100:00:16,000 --> 00:00:19,000When I was 10 ye

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/03 04:13:39
关于perl的问题
现有a文件
1
00:00:16,000 --> 00:00:19,000
When I was 10 years old,
2
00:00:19,000 --> 00:00:22,000
a cousin of mine took me on a tour of his medical school.
3
00:00:22,000 --> 00:00:24,000
And as a special treat
4
00:00:24,000 --> 00:00:26,000
he took me to the pathology lab
5
00:00:26,000 --> 00:00:28,000
and took a real human brain
6
00:00:28,000 --> 00:00:30,000
out of the jar
7
00:00:30,000 --> 00:00:32,000
and placed it in my hands.
b文件
1
00:00:16,000 --> 00:00:19,000
我十岁的时候
2
00:00:19,000 --> 00:00:22,000
我的一个表兄带我参观了他上的医学院
3
00:00:22,000 --> 00:00:24,000
作为一次特别优待
4
00:00:24,000 --> 00:00:26,000
他带我去了病理学实验室
5
00:00:26,000 --> 00:00:28,000
拿出一个真正的人脑
8
00:00:28,000 --> 00:00:30,000
从一个罐子里
9
00:00:30,000 --> 00:00:32,000
把它放在了我手里
然后将a文件以句号为分割,时间轴合并,提取出了
c文件
1
00:00:16,000 --> 00:00:22,000?1
When I was 10 years old,
a cousin of mine took me on a tour of his medical school.
2
00:00:22,000 --> 00:00:32,000
And as a special treat
he took me to the pathology lab
and took a real human brain
out of the jar
and placed it in my hands.
怎么从b文件中提取出与c文件对应的中文文本d文件呢,时间轴以英文a文件的为依据如下:
d文件
1
00:00:16,000 --> 00:00:22,000?1
我十岁的时候,
我的一个表兄带我参观了他上的医学院.
2
00:00:22,000 --> 00:00:32,000
作为一次特别优待,
他带我去了病理学实验室,
拿出一个真正的人脑,
从一个罐子里,
把它放在了我手里.
暂时先这么多分,好的话,一定会再加的,
#!/usr/bin/perl
#abcd.pl
my ($i,$num,$file)=(1,0,'');
open A,"afile";
while(){ push @index,$. if /\.$/ }
open B,"bfile";
my @B=;
$B[($_ - 1)] =~ s/$/./ for @index;
$file .= $_ for @B;
my @D=split/\./,$file;
for (@D){
/^(\d\d:.*?) -->(?:.*)* (\d\d.*?\d)$/sm;
my ($t1,$t2)=($1,$2);
s/^\d+(:.*)?$//gm;
s/\n+/\n/mg;
s/^(\D.*\D)$/$1,/mg;
s/,$/./;
print ++$num,"\n","$t1 --> $t2",$_,"\n";
}

perl abcd.pl
1
00:00:16,000 --> 00:00:22,000
我十岁的时候,
我的一个表兄带我参观了他上的医学院.
2
00:00:22,000 --> 00:00:32,000
作为一次特别优待,
他带我去了病理学实验室,
拿出一个真正的人脑,
从一个罐子里,
把它放在了我手里.
正则表达式是 Perl 语言的一大特色,也是 Perl 程序中的一点难点,不过如果能够很好的掌握他,就可以轻易地用正则表达式来完成字符串处理的任务,当然在设计中就更能得心应手了.
perl菜鸟,请指教
再问: 额……怎么运行啊,几个文件是在不同的文件里的,比如a.txt b.txt c.txt
再答: 运行啊?? perl abcd.pl 啊 作为一次特别优待, 艾??怎说捏?把afile 改成a.txt 把bfile 改成b.txt
再问: 看一开始你的就是这意思,试过,没产生啥作用么
再答: afile bfile abcd.pl 几个文件是在同的 dir 里 怎说捏?如果你还没有找到? afile ============ 1 00:00:16,000 --> 00:00:19,000 When I was 10 years old, 2 00:00:19,000 --> 00:00:22,000 a cousin of mine took me on a tour of his medical school. 3 00:00:22,000 --> 00:00:24,000 And as a special treat 4 00:00:24,000 --> 00:00:26,000 he took me to the pathology lab 5 00:00:26,000 --> 00:00:28,000 and took a real human brain 6 00:00:28,000 --> 00:00:30,000 out of the jar 7 00:00:30,000 --> 00:00:32,000 and placed it in my hands. bfile ================== 1 00:00:16,000 --> 00:00:19,000 我十岁的时候 2 00:00:19,000 --> 00:00:22,000 我的一个表兄带我参观了他上的医学院 3 00:00:22,000 --> 00:00:24,000 作为一次特别优待 4 00:00:24,000 --> 00:00:26,000 他带我去了病理学实验室 5 00:00:26,000 --> 00:00:28,000 拿出一个真正的人脑 8 00:00:28,000 --> 00:00:30,000 从一个罐子里 9 00:00:30,000 --> 00:00:32,000 把它放在了我手里 perl abcd.pl >dfile you 可以试试