理解循环问题的perl

发布于 2025-02-08 14:10:13 字数 256 浏览 1 评论 0原文

我正在寻找一些旧的perl代码,并且正在试图弄清楚这一语句的含义是什么 - 我已经完成了编程,但没有在perl中进行编程。对此陈述的艰难时期实际上意味着什么。

for ($xx = $x+1 ; $contents[$xx] !~ m/^\:1S\:XXX/  ; $xx++)

是否循环直到找到:1s:xxx

如果不是),那是什么意思?

有人可以帮忙吗?

谢谢

I'm looking at some old Perl code and I'm trying to figure out what does this statement exaclty mean - I have done programming, but not in Perl. Having a hard time with what this for statement actually means.

for ($xx = $x+1 ; $contents[$xx] !~ m/^\:1S\:XXX/  ; $xx++)

Is this looping until it finds :1S:XXX

If not, then what does this mean?

Can someone help with this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2025-02-15 14:10:13

这可能更加清楚:

$xx = $x+1;
$xx++ until substr($contents[$xx], 0, 7) eq ':1S:XXX';

但是,如果找不到,则永远不会找到 code>,如果找不到:xxx 。因此,如果在$ x+1的起点时或之后,在数组元素的开头找不到搜索的字符串,则我会考虑将$ xx定义。

use List::Util 'first';
my $xx = first { $contents[$_] =~ /^:1S:XXX/ } $x+1 .. @contents-1;

在Perl Regexes 中:可以在前面具有\,但不需要它。

This might be more clear:

$xx = $x+1;
$xx++ until substr($contents[$xx], 0, 7) eq ':1S:XXX';

However both this and your for loops forever if :1S:XXX isn't found. So I would consider this which leaves $xx not defined if the searched string isn't found at the beginning of an array element at or after the starting point in $x+1.

use List::Util 'first';
my $xx = first { $contents[$_] =~ /^:1S:XXX/ } $x+1 .. @contents-1;

In perl regexes : can have \ in front but don't need it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文