如何从数组中删除所有undefs?

时间:2021-05-18 07:42:20

While reading from a configuration file in Perl there might be cases when a line is invalid and it does not need to get added to my array of valid lines. Since I'm using a for loop here, even the invalid lines create an undef entry. How can I remove all them afterwards?

从Perl中的配置文件中读取时,可能会出现行无效且无需添加到有效行数组的情况。由于我在这里使用for循环,即使是无效行也会创建一个undef条目。我怎样才能将它们全部删除?

Thanks!

谢谢!

1 个解决方案

#1


42  

@array = grep defined, @array;

#1


42  

@array = grep defined, @array;