我總是感到困惑或不知道如何在Perl中處理哈希。Perl推送哈希值
所以現在的問題是,
考慮整個事情,我試圖在下面的哈希更改密鑰名稱。 %new_hash的
my %hash_new = {
'customername' => 'Lee & toys',
'employee_name' => 'Checngwang',
'customer_id' => 'X82349K',
'customer_address' => 'classic denver ranch, meadows drive',
'types' => 'category la',
};
my %selectCols = ('customername' => 'CUSTOMERNAME','employee_name' => 'EMP_NAME','customer_id' => 'cusid','customer_address' => 'cusaddr','types' => 'Typs');
my %new_hash =();
foreach my $hash_keys (keys %hash_new){
my $newKey = $selectCols{$hash_keys};
$new_hash{$newKey} = $hash_new{$hash_keys};
}
print Dumper %new_hash;
輸出是一樣的東西連續串如下的鍵值組合,
CUTOMERNAMELee & toysEMP_NAMEChecngwangcus_idX82349Kcusaddrclassic denver ranch, meadows driveTypscategory la
但不是這個,我需要的哈希一樣,
$VAR1 = {
'CUSTOMERNAME' => 'Lee & toys',
'EMP_NAME' => 'Checngwang',
'cusid' => 'X82349K',
'cusaddr' => 'classic denver ranch, meadows drive',
'Typs' => 'category la',
};
請幫助我解決這個問題!
對不起,你將不得不擴大一點 - 我不能跟隨你所問的。我的代碼示例中沒有看到任何打印語句。 – Sobrique
你很好!我剛剛更新了打印聲明 – Raja
我很困惑。你的輸入是什麼?期望的輸出是什麼? – yonyon100