View Single Post
  #2 (permalink)  
Old August 19th, 2009, 10:47 PM
Leigh Leigh is offline
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A really inefficient way to do it is simply to loop over the array and discard anything which is empty:

Code:
use strict;
use warnings;
my @array=("abc", "def", "", "ghij");
my @temp_array;
foreach(@array) {
	if ($_) {
		push(@temp_array, $_);
	}
}
@array=@temp_array;
print join(", ", @array)."\n";
Yields:
Code:
C:\Temp>perl remove_elements.pl
abc, def, ghij
There's a better way to do it using a hash, but it escapes me at the moment....
Reply With Quote