带有虚拟占位符的 Perl 赋值 [英] Perl assignment with a dummy placeholder
问题描述
在我使用过的其他语言(如 Erlang 和 Python)中,如果我正在拆分字符串并且不关心其中一个字段,我可以使用下划线占位符.我在 Perl 中试过这个:
In other languages I've used like Erlang and Python, if I am splitting a string and don't care about one of the fields, I can use an underscore placeholder. I tried this in Perl:
(_,$id) = split('=',$fields[1]);
但我收到以下错误:
无法修改 ./generate_datasets.pl 第 17 行,靠近);"的列表赋值中的常量项
由于编译错误,./generate_datasets.pl 的执行中止.
Can't modify constant item in list assignment at ./generate_datasets.pl line 17, near ");"
Execution of ./generate_datasets.pl aborted due to compilation errors.
Perl 是否有类似的这样的模式,我可以使用它来代替创建无用的临时变量?
Does Perl have a similar such pattern that I could use instead of creating a useless temporary variables?
推荐答案
undef
在 Perl 中起到相同的作用.
undef
serves the same purpose in Perl.
(undef, $something, $otherthing) = split(' ', $str);
这篇关于带有虚拟占位符的 Perl 赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!