Re: Remove whitespace elements of an array.
From: Tore Aursand (tore_at_aursand.no)
Date: 03/31/04
- Next message: Garry Heaton: "Module compilation misery"
- Previous message: Paul Lalli: "Re: Remove whitespace elements of an array."
- In reply to: fenisol3: "Remove whitespace elements of an array."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Garry Heaton: "Module compilation misery"
- Previous message: Paul Lalli: "Re: Remove whitespace elements of an array."
- In reply to: fenisol3: "Remove whitespace elements of an array."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|