Perl“如果”陈述
现在,我有以下 Perl 代码
my $tmpl1="download1_video.html"
if $file->{file_name}=~/\.(avi|divx|mkv|flv|mp4|wmv)$/i;
$tmpl1||="download1.html";
,因此它会检查该文件是否是视频,如果是,则将其定向到特定页面。尽管我只是想知道如何在其中添加另一个 if 语句来检查扩展名是否为 .mp3,如果是,则将其定向到 download1_audio.html。
Right now, I have the following Perl code
my $tmpl1="download1_video.html"
if $file->{file_name}=~/\.(avi|divx|mkv|flv|mp4|wmv)$/i;
$tmpl1||="download1.html";
so it's checking to see if the file is a video, and if so it directs it to the certain page. Although I'm just wondering how I can add another if statement in there to check if the extension is .mp3, and if so direct it to download1_audio.html.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是您所需要的吗?
Is this what you needed ?
一种更奇特的方法是预先创建一个由文件类型键入的哈希值,其中包含下一页所需的信息;我猜的文件名?
A fancier way would be to create a hash keyed by your file types in advance with the info you needed for your next page; the filename I guess?
刚刚被这个问题困扰,我必须建议您不要使用条件修饰符声明变量。如果条件不成立,它将运行另一个子句的no部分,这意味着您没有声明
$tmpl1
,但是因为它已经通过了严格,它允许您分配到内存中未定义的位置。有一种更安全的方法可以完成您的前任在这里所做的事情,这仍然可以说明解决方案。
因此,
$tmpl1
始终被声明$tmpl1
始终被赋值Having just been burnt by this, I must advise you against declaring a variable with a conditional modifier. If the condition does not hold true, it runs no part of the other clause, which means that you are not declaring
$tmpl1
, but since it's already passed strict, it allows you to assign to an undefined position in memory.There is a safer way to do what your predecessor is doing here, that can yet illustrate a solution.
Thus,
$tmpl1
is always declared$tmpl1
is always assigned a value