$ cat del.pl
#! /usr/local/bin/perl -w
print "perl version is ", $], "\n";
@array=(a_b, a_c, a_d);
for ($index=0; $index <= $#array; $index++) {
if (exists $array[$index]) {
print "index = ", $index, " element = ", $array[$index], "\n";
} else {
print "index = ", $index, " element is not there", "\n";
}
}
delete $array[1];
for ($index=0; $index <= $#array; $index++) {
if (exists $array[$index]) {
print "index = ", $index, " element = ", $array[$index], "\n";
} else {
print "index = ", $index, " element is not there", "\n";
}
}
$ ./del.pl
perl version is 5.006001
index = 0 element = a_b
index = 1 element = a_c
index = 2 element = a_d
index = 0 element = a_b
index = 1 element is not there
index = 2 element = a_d
$
I don't understand what you are trying to do, actually.
Just bear in mind:
To really delete an item from an array, such as (1, 2, 3) -> (1, 3), use splice().
delete() simply sets the elements as "undef". Unless the elements happen to appear at the end of the array, they will not be removed, and is usually not what you want. delete() is usually more meaningful for hashes to remove hash items, NOT array items.
As I'm not sure what you exactly would like to do, you may need to figure out the problem yourself. You may read the manpage for delete() for the complete details.