in reply to deleting array elements(efficiency/critique)
Here's a solution where the source index is the loop variable, and the destination follows behind it:
my $p = 0; for (my $q = 0; $q < @{$mon_obj->{'FILE_DATA'}}; ++$q) { if (defined $mon_obj->{'FILE_DATA'}->[$q]) { $mon_obj->{'FILE_DATA'}->[$p] = $mon_obj->{'FILE_DATA'}->[$q] if $p != $q; $p++; } } splice @{$mon_obj->{'FILE_DATA'}}, $p;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: deleting array elements(efficiency/critique)
by blueAdept (Beadle) on Dec 27, 2000 at 23:14 UTC |