Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove all undefs from array?

Tags:

arrays

perl

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?

Thanks!

like image 300
flohei Avatar asked Jun 20 '12 15:06

flohei


People also ask

How to remove array element in Perl?

In Perl, the splice() function is used to remove and return a certain number of elements from an array. A list of elements can be inserted in place of the removed elements.


1 Answers

@array = grep defined, @array;
like image 175
mob Avatar answered Oct 09 '22 23:10

mob