best way to eliminate a row in a multidimensional array

J

Jack

Hi I want to take out an entire row of a multidim array (everything
about it) and have the row below "assume" the row and index numbers
(and any other subsequent rows also would move up 1 with their
indices)..

Also, I am looking for a good way to count the number of rows in a
given multidim array..

Curious how this can be done.

Thank you,

Jack
 
T

Tore Aursand

Hi I want to take out an entire row of a multidim array (everything
about it) and have the row below "assume" the row and index numbers
(and any other subsequent rows also would move up 1 with their
indices)..

What have you tried so far? What didn't work? How about something like
the code below?

sub remove_array_element {
my $array = shift;
my $index = shift || 0;

my @array = ();
for ( 0..$#$array ) {
push( @array, $array->[$_] ) unless ( $_ == $index );
}

return \@array;
}


--
Tore Aursand <[email protected]>
"Have you ever had a dream, Neo, that you were so sure was real? What
if you were unable to wake from that dream? How would you know the
difference between the dream world and the real world?" (Morpheus, The
Matrix)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top