作业帮 > 综合 > 作业

关于perl的问题 100:00:09,855 --> 00:00:14,724Britain was an objec

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/19 04:42:10
关于perl的问题
1
00:00:09,855 --> 00:00:14,724
Britain was an object of desire.
2
00:00:26,295 --> 00:00:31,847
Tacitus declared it worth the conquest,
3
00:00:32,015 --> 00:00:35,803
the best compliment
that could occur to a Roman.
如果以句号为分割,把对应的时间合并起来,最后得到下面的结果:
1
00:00:09,855 --> 00:00:14,724
Britain was an object of desire.
2
00:00:26,295 --> 00:00:35,803
Tacitus declared it worth the conquest,
the best compliment
that could occur to a Roman.
perl菜鸟,望指教
#!/usr/bin/perl
#f3.pl
my $file;
while (){s/^\s+$//;$file.=$_};
my @data=split/\./,$file;
pop @data;
for (@data){
/^(\d\d:.*?) -->(?:.*)* (\d\d.*?\d)$/sm;
my ($t1,$t2)=($1,$2);
s/^\d+(:.*)?$//gm;
s/$/./;
s/\n+/\n/g;
print ++$num,"\n","$t1 --> $t2",$_,"\n";
}

1
00:00:09,855 --> 00:00:14,724
Britain was an object of desire.
2
00:00:26,295 --> 00:00:35,803
Tacitus declared it worth the conquest,
the best compliment
that could occur to a Roman.
正则表达式是 Perl 语言的一大特色,也是 Perl 程序中的一点难点,不过如果能够很好的掌握他,就可以轻易地用正则表达式来完成字符串处理的任务,当然在设计中就更能得心应手了.
perl菜鸟,请指教