19

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!

flohei
  • 5,248
  • 10
  • 36
  • 61
  • 1
    if you're creating the config file use a module like Config::Simple. If you're reading the content of a pre-existing config file into an array why are you pushing invalid entries into your array instead of skipping them? – beresfordt Jun 20 '12 at 15:42

1 Answers1

56
@array = grep defined, @array;
mob
  • 117,087
  • 18
  • 149
  • 283