如何从Perl中的哈希中删除键?

Bal*_*aji 1 perl hash perl-data-structures

如何从现有地图中删除密钥?

if (exists $sampleMap{1})
{
      #Here I want to remove the "1" key from sampleMap
}
Run Code Online (Sandbox Code Playgroud)

Nik*_*ain 7

使用delete删除的哈希键:

if (exists $sampleMap{1})
{
      delete $sampleMap{1}; #Here I want remove the "1" key from sampleMap.
}
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请查看删除.

  • 您不需要检查密钥是否存在,如果不存在,delete() 也不会抱怨。 (3认同)