coldfingertips has asked for the wisdom of the Perl Monks concerning the following question:
PERL Black Book mentions you can delete $array[index], it doesn't say there are limitations or anything. It makes it sound like you can delete ANY element by doing it like this but someone in the room said otherwise. Can someone explain this to me?
I have an array with blank values and I cannot get rid of them with grep, delete splice. To see what was actually contained that was causing problems, I used print "This is what we found: \"\""; and the result comes back literally "This is what we found: "". So it's empty and/or undefined.
Things I have tried:
@n = grep $_, @n;
@n = grep defined, @n;
@n = grep defined and length, @n;
for(my $count = 0; $count < @myarray; ) { unless(defined $myarray[$count]) { splice @myarray, $count, 1; } else{ $count++ } }
my $count = -1; foreach(@myarray) { $count++; if (!defined $_) { splice(@myarray,$count); #delete $myarray[$count]; } } No matter which of these I use, when I print out the array I get a han +dful of "Use of uninitialized value at line 55". Anyone have any sug +gestions as to why these little buggers won't go away?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing null values from within an array
by davido (Cardinal) on Mar 06, 2004 at 05:04 UTC | |
|
Re: Removing null values from within an array
by Mr. Muskrat (Canon) on Mar 06, 2004 at 04:45 UTC | |
|
What it means to define and to delete array elements
by TomDLux (Vicar) on Mar 06, 2004 at 07:00 UTC | |
|
Re: Removing null values from within an array
by Roger (Parson) on Mar 06, 2004 at 15:54 UTC | |
|
Re: Removing null values from within an array
by sgifford (Prior) on Mar 06, 2004 at 20:14 UTC | |
|
Re: Removing null values from within an array
by sulfericacid (Deacon) on Mar 06, 2004 at 10:17 UTC | |
by TomDLux (Vicar) on Mar 07, 2004 at 03:45 UTC | |
|
Re: Removing null values from within an array
by runrig (Abbot) on Mar 06, 2004 at 16:25 UTC |