Re: Remove whitespace elements of an array.

From: Tore Aursand (tore_at_aursand.no)
Date: 03/31/04


Date: Wed, 31 Mar 2004 00:11:24 +0200

On Tue, 30 Mar 2004 16:45:39 -0500, fenisol3 wrote:
> What I am trying to do is to go through each element in an array using
> foreach loop, delete the elements that are empty (blank spaces), and store
> the rest in another array. For some reason, (@array = grep /\S/, @array)
> doesn't do anything to the array.

You still don't tell us anything about what you've tried so far. What
doesn't work? What have you tried?

The simples approach - at least for me - would be something like this:

  my @old = ( 'a', 'b', '', 'c', ' ', 'd' );
  my @new;

  foreach ( @old ) {
      if ( /\S/ ) {
          push( @new, $_ );
      }
  }

This can easily have been cut down to:

  foreach ( @old ) {
      push( @new, $_ ) if ( /\S/ );
  }

...and again to:

  my @new = grep /\S/, @old;

If none of these suggestions work, you're not describing your problem
sufficiently. Please do that next time you post here. Give us some
example data and what you have tried so far (which doesn't work).

-- 
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
 4 will be fought with sticks and stones." -- Albert Einstein


Relevant Pages

  • When was the second world war named?
    ... I've tried to research this a bit but have come up empty. ... that another world war was being fought or had been fought? ... what some of the first media to refer to it as the second world war ... I guess it leads on to the question of when the 'Great War' ...
    (soc.history.war.world-war-ii)
  • Re: How to copy non-contiguous columns to a text file
    ... a single output string could theoretically exceed the limits of the String data type. ... Unlikely as all that might seem, I refer to design algorithms that do not break when expected limits are exceeded. ... I vaguely remember that some other applications requires the empty line at the end when they import the file. ... The last line, then, should be the Record.Count since the first record is elementof the array. ...
    (microsoft.public.excel)
  • Re: Macros in php
    ... From the PHP manual for empty: ... "The following things are considered to be empty: ... array() ... practice in PHP. ...
    (comp.lang.php)
  • Re: Index from TM
    ... And the intersection of my chosen cell and the A1:A9 range was an ... These arguments can be either defined, empty or omitted. ... The array_ argument has been defined, ... If the indexed array was C22:C25 the relative sequential positions would be ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Index from TM
    ... Microsoft Excel MVP ... And the intersection of my chosen cell and the A1:A9 range was an ... These arguments can be either defined, empty or omitted. ... The array_ argument has been defined, ...
    (microsoft.public.excel.worksheet.functions)