Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在perl中用另一个名称替换哈希键_Perl_Hash_Substitution - Fatal编程技术网

在perl中用另一个名称替换哈希键

在perl中用另一个名称替换哈希键,perl,hash,substitution,Perl,Hash,Substitution,我正试图用另一个名字换钥匙。尝试了以下代码,但出现了一些错误: my @array = qw(1 hello ue hello 3 hellome 4 hellothere); my %hash = @array; foreach (Keys %hash) { s/ue/u/g; } 输出错误:test.pl第35行的模零非法。Perl区分大小写。您正在查找(小写): 为了进一步收紧代码,实际上不需要遍历键来确定是否存在特定键。以下单条线路可替代for回路: $hash{u} = d

我正试图用另一个名字换钥匙。尝试了以下代码,但出现了一些错误:

my @array = qw(1 hello ue hello 3 hellome 4 hellothere);
my %hash = @array;

foreach (Keys %hash) { 
   s/ue/u/g;
}

输出错误:test.pl第35行的模零非法。

Perl区分大小写。您正在查找(小写):

为了进一步收紧代码,实际上不需要遍历键来确定是否存在特定键。以下单条线路可替代for回路:

$hash{u} = delete $hash{ue} if exists $hash{ue};

Perl区分大小写。您正在查找(小写):

为了进一步收紧代码,实际上不需要遍历键来确定是否存在特定键。以下单条线路可替代for回路:

$hash{u} = delete $hash{ue} if exists $hash{ue};
$hash{u} = delete $hash{ue} if exists $hash{ue};