迭代 Perl 集合,计算新值
我有一个 Perl 脚本,其中包含以下行:
print $_->{label} || $_->{irq}, "=", $_->{count}, "; " for @irqs;
其中 @irqs
是某种集合(我不是 Perl 程序员),它被 push
到其他位置程序。
我有另一个哈希集合,其中键等于 $_->{label}
或 $_->{irq}
的值来自@irqs
集合。
我不想在上面的语句中打印 $_->{count}
,而是打印 $_->{count} - X
where X
是哈希值。
我确信我可以通过手动迭代 @irqs
并按下 $_->{label}
或 $_->{ irq}
到具有计算值的新集合上,但是,有更好的方法吗?
正如我所说,我不是 Perl 程序员,所以我只是想在开始之前确保我走的是正确的道路......
I have a Perl script which has the following line in it:
print $_->{label} || $_->{irq}, "=", $_->{count}, "; " for @irqs;
Where @irqs
is some kind of collection (I am not a Perl programmer) that is push
ed to elsewhere in the program.
I have another collection which is a hash, where the key is equal to either the value of $_->{label}
or $_->{irq}
from the collection @irqs
.
Instead of printing $_->{count}
in the above statement, I would like to print $_->{count} - X
where X
is the value from the hash.
I am sure that I can do this by iterating through @irqs
by hand and pushing either $_->{label}
or $_->{irq}
onto a new collection with the calculated value, but, is there a better way to do it?
As I said, I'm not a Perl programmer, so I just wanted to make sure I was going down the correct path before starting out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要复制/存储任何其他数据即可执行此操作。
You don't need to copy/store any additional data to do this.