Thanks for pointing out that "delete $array[$idx]" is deprecated, and generates undefs.
Just to illustrate the subtle behaviour that was masked in my previous post, here is a demo of potential disaster the appearance of the undef could cause:
perl -MData::Dumper -E 'my $r=[map { id=>$_ }, ("b","a".."c","b")];
say Dumper $r;
my %h;
$h{$r->[$_]{id}}++ and delete $r->[$_] for 0..$#$r;
say Dumper $r'
--- SECOND (Relevant) PART of OUTPUT---
$VAR1 = [
{
'id' => 'b'
},
{
'id' => 'a'
},
undef,
{
'id' => 'c'
}
];
What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
-Larry Wall, 1992
|