Changing keys in a “for ( keys %hash ) {}”-loop

后端 未结 5 487
终归单人心
终归单人心 2021-01-14 08:12

I remember something about not changing the keys in a

for my $key ( keys %hash ) { ...

for example

for my $key ( keys %hash         


        
5条回答
  •  旧时难觅i
    2021-01-14 08:33

    you cannot rename any key value instead you can delete and create a new one which is not lesser than renaming a key! :-)

    for my $key ( keys %hash ) {
        delete $hash{$key}; 
        $hash{$key} = "$key_x";
    }
    

提交回复
热议问题