A slice of an empty list is still an empty list. Thus:
@a = ()[1,0]; # @a has no elements
@b = (@a)[0,1]; # @b has no elements
But:
@a = (1)[1,0]; # @a has two elements
@b = (1,undef)[1,0,2]; # @b has three elements
More generally, a slice yields the empty list if it indexes only beyond the end of a list:
@a = (1)[ 1,2]; # @a has no elements
@b = (1)[0,1,2]; # @b has three elements
####
use strict;
use warnings;
use 5.014;
use Data::Dumper;
my %hash = ('hello', 1, 'goodbye', 2, 'world', 3, 'mars', 4);
@hash{'goodbye', 'world'} = ();
say Dumper(\%hash);
--output:--
$VAR1 = {
'mars' => 4,
'hello' => 1,
'world' => undef,
'goodbye' => undef
};
####
$VAR1 = {
'mars' => 4,
'hello' => 1,
};
####
my @arr = (10, 20, 30, 40);
@arr[1, 2] = ();
say Dumper(\@arr);
--output:--
$VAR1 = [
10,
undef,
undef,
40
];