where $i is the element u wish to remove...undef $array[$i]
This will not actually remove an element from the array, but will set the value to undef, which will mean that $array[$i] is not defined. scalar @array will still return the same number as before. Here's an example:
my @array = qw( 1 2 3 4 ); print "there are ".scalar(@array)." elements in \@array \n"; print "the last index of \@array is $#array \n"; print "the 3'rd (index 2) value of \@array is $array[2] \n"; undef $array[2]; print "\$array[2] is now undefined \n" if not defined $array[2]; print "there are STILL ".scalar(@array)." elements in \@array \n"; print "the last index of \@array is STILL $#array \n";
In reply to Re: How do I completely remove an element from an array?
by screamingeagle
in thread How do I completely remove an element from an array?
by vroom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |