关于perl的问题 100:00:09,855 --> 00:00:14,724Britain was an object of desire.200:00:26,295 --> 00:00:31,847Tacitus declared it worth the conquest,300:00:32,015 --> 00:00:35,803the best complimentthat could occur to a Roman.如果以句号为分

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 05:10:22

关于perl的问题 100:00:09,855 --> 00:00:14,724Britain was an object of desire.200:00:26,295 --> 00:00:31,847Tacitus declared it worth the conquest,300:00:32,015 --> 00:00:35,803the best complimentthat could occur to a Roman.如果以句号为分
关于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菜鸟,望指教

关于perl的问题 100:00:09,855 --> 00:00:14,724Britain was an object of desire.200:00:26,295 --> 00:00:31,847Tacitus declared it worth the conquest,300:00:32,015 --> 00:00:35,803the best complimentthat could occur to a Roman.如果以句号为分
#!/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菜鸟,请指教

这个是字幕吧,找个字幕编辑软件也许就有相应的功能了,一定要用perl做么?
我也是初学perl,水平不够。
写个一般的程序得查文档折腾好久,完了还得调试。
给你建议个方案吧:
1)设置3个变量分别用来存放 序号;时间轴(00:00:26,295 --> 00:00:35,803);台词(Tacitus declared it worth the conquest,)...

全部展开

这个是字幕吧,找个字幕编辑软件也许就有相应的功能了,一定要用perl做么?
我也是初学perl,水平不够。
写个一般的程序得查文档折腾好久,完了还得调试。
给你建议个方案吧:
1)设置3个变量分别用来存放 序号;时间轴(00:00:26,295 --> 00:00:35,803);台词(Tacitus declared it worth the conquest,)
初始化变量,序号为0,时间轴,台词为空字符串
2)设置另一变量 $flag 作为标记用
3)循环每次读入一行文本, 如果文本末尾是句号,就把$flag设置为1,否则$flag设置为0
4)对读入的文本进行正则匹配,
如果是时间轴(包含->), 就连到 时间轴变量后面(.)
如果是台词(行首是字母),就连到台词变量后面(.)
其他情况就next
5)然后判断$flag的值,如果为1,
就把序号变量值加1
对时间轴变量进行处理, 正则表达式匹配 第一个-->以前的文本,还有最后一个-->以后的文本,中间
再加上-->就成了新的时间轴
然后依次输出以下内容到新文件中:
序号变量,\n
处理好的新时间轴
台词变量
输出完毕后清空 时间轴变量, 台词变量
6)如果$flag变量为0, next
以上就是我的思路,供你参考.
如果很熟悉perl的话,应该几分钟就能写好.我是不行了.
第一次在百度知道上写这么长的回复...

收起