如何在Perl中跳过“死” [英] How to skip 'die' in perl

查看:87
本文介绍了如何在Perl中跳过“死”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用perl API从网站提取数据。该过程将使用uris列表作为输入。然后,我从网站上提取每个uri的相关信息。如果没有提供一个uri的信息,它将死亡。类似于下面的代码

I am trying to extract data from website using perl API. The process is to use a list of uris as input. Then I extract related information for each uri from website. If the information for one uri is not present it dies. Some thing like the code below

my @tags = $c->posts_for(uri =>"$currentURI");
die "No candidate related articles\n" unless @tags;

现在,我不希望程序在没有任何标签的情况下停止运行。我希望程序跳过该特定的uri,然后转到下一个可用的uri。我该怎么做?
谢谢您的时间和帮助。

Now, I don't want the program to stop if it doesn't get any tags. I want the program to skip that particular uri and go to the next available uri. How can i do it? Thank you for your time and help.

谢谢
Sammed

Thank you, Sammed

推荐答案

好吧,假设您处于依次处理每个URI的循环中,则应该能够执行以下操作:

Well, assuming that you're inside a loop processing each of the URIs in turn, you should be able to do something like:

next unless @tags;

例如,以下程序仅打印数字行:

For example, the following program only prints lines that are numeric:

while (<STDIN>) {
    next unless /^\d+$/;
    print;
}

循环依次处理每条输入行,但,当发现一个与该正则表达式(全数字)不匹配的表达式时,它将重新启动循环(对于下一个输入行)而不进行打印。

The loop processes every input line in turn but, when one is found that doesn't match that regular expression (all numeric), it restarts the loop (for the next input line) without printing.

相同的方法上面的第一个代码块中使用,如果没有标签,则重新启动循环,移至下一个URI。

The same method is used in that first code block above to restart the loop if there are no tags, moving to the next URI.

这篇关于如何在Perl中跳过“死”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆