J
Jerry Krinock
In at least one other language, I read that it is not safe to delete
array or dictionary elements while iterating through it. Obviously,
this could cause trouble. Is this safe to do with a hash in perl?
Example: The following sub works OK, but is it guaranteed safe?
sub removeEmptyStringValuesFromHashRef {
my $hashRef = shift ;
while (my ($key, $value) = each(%$hashRef)) {
if (defined($value)) {
if (length($value) == 0) {
delete ($hashRef->{$key}) ;
}
}
}
}
array or dictionary elements while iterating through it. Obviously,
this could cause trouble. Is this safe to do with a hash in perl?
Example: The following sub works OK, but is it guaranteed safe?
sub removeEmptyStringValuesFromHashRef {
my $hashRef = shift ;
while (my ($key, $value) = each(%$hashRef)) {
if (defined($value)) {
if (length($value) == 0) {
delete ($hashRef->{$key}) ;
}
}
}
}