Y
Yehuda Berlinger
This one is a surprise:
@a = (0,undef);
@b = (1,2);
@c[@a] = @b;
I was hoping to see $c[0] == '1', but I got '2'. Apparently, undef is
converted to '0' when used as an array subscript. Is this documented
anywhere, or is it something too obvious to document? I coudn't find
it in the usual places.
I was hoping to avoid doing a loop such as:
@bb = @b;
foreach $a (@a) {
my $b = shift @bb;
next unless defined $a;
$c[$a] = $b;
}
Any thoughts?
Yehuda
@a = (0,undef);
@b = (1,2);
@c[@a] = @b;
I was hoping to see $c[0] == '1', but I got '2'. Apparently, undef is
converted to '0' when used as an array subscript. Is this documented
anywhere, or is it something too obvious to document? I coudn't find
it in the usual places.
I was hoping to avoid doing a loop such as:
@bb = @b;
foreach $a (@a) {
my $b = shift @bb;
next unless defined $a;
$c[$a] = $b;
}
Any thoughts?
Yehuda