in reply to Removal of "NULL" element in an array?
By "NULL," do you mean only undefined items or also the empty ones?
If you want to exclude only the items that are not defined, then use
my @clean = grep { defined } @data;
If you want to skip the empty items, then use
my @clean = grep { $_ ne '' } @data;
However, the above code will break on undefined items. If you want to combine both approaches, then the "right" approach is:
#!/usr/bin/perl -w use strict; my @data= (1, 2, 3, 'a', undef, 4, '', 5, 'b'); my @clean = grep { defined && $_ ne '' } @data; print join ",", @clean; print "\n";
output:
1,2,3,a,4,5,b
HTH
cchampion
|
|---|