如何从数组中删除所有undef? [英] How do I remove all undefs from array?

查看:119
本文介绍了如何从数组中删除所有undef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Perl中读取配置文件时,可能会出现一行无效并且不需要将其添加到我的有效行数组中的情况.由于我在这里使用for循环,因此即使无效的行也会创建undef条目.以后如何删除所有这些?

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?

谢谢!

推荐答案

@array = grep defined, @array;

这篇关于如何从数组中删除所有undef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆