How do I remove all undefs from array?

人走茶凉 提交于 2019-12-18 12:14:45

问题


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?

Thanks!


回答1:


@array = grep defined, @array;


来源:https://stackoverflow.com/questions/11122977/how-do-i-remove-all-undefs-from-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!