http://www.perlmonks.org?node_id=474932


in reply to Re: Pop/shift/delete on array
in thread Pop/shift/delete on array

The delete operator doesn't really belong in the list. It removes pairs from a hash, but on an array it only undefines the value of an element.
This is not quite true. If you delete the last element of an array, the array will actually shrink:
my @array = qw/tiger dog cat/; delete $array[2]; print scalar @array; # Output is 2
You can even have it funnier:
my @array = qw/tiger dog cat/; delete $array[1]; print scalar @array; # Output is 3 delete $array[2]; print scalar @array; # Output is 1
However, this seemingly equivalent code does behave weird:
my @array = qw/tiger dog cat/; delete $array[1]; print scalar @array; # Output is 3 splice @array, 2; print scalar @array; # Output is 2