如何检查Perl中的哈希中是否存在密钥?

YoD*_*Dar 2 perl hash exists

我想检查参数$PGkey是否等于哈希表中具有相同名称的键.此外,我希望尽可能接近这种格式:

while(<PARAdef>) {
    my($PGkey, $PGval) = split /\s+=\s+/;
    if($PGkey == $hash{$PGkey}) {
        print PARAnew "$PGkey = $hash{$PGkey}->[$id]\n";
    } else {
        print PARAnew "$PGkey = $PGval\n";
    }
}
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法吗?

cha*_*aos 15

检查哈希密钥存在的方法是:

exists $hash{$key}
Run Code Online (Sandbox Code Playgroud)