in reply to Re: Remove empty element.
in thread Remove empty element.

Or grep away null elements. I admit that I do this sometimes simply to save cognitive load as opposed to CPU load.
my @array = ('',1,2,'',3,'',4); @array = grep { $_ } @array; print join "}{",@array; print "\n";
gives
1}{2}{3}{4

Replies are listed 'Best First'.
Re^3: Remove empty element.
by afoken (Chancellor) on Jul 14, 2009 at 19:38 UTC
    @array = grep { $_ } @array;

    This grep also removes array elements that happen to be 0. Use grep { defined && length } instead if you want to have the 0 elements in the result.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Good catch - in this case there aren't any, but you're still right. :)