ããã·ã¥ãçµåãã
åèªé »åº¦ãæ±ãã¨ï¼ããã·ã¥ãçµåããããªãï¼ãã¡ãã¡èªå·±æµãã¸ãã¯ãæ¸ãã¦ããããã©ï¼ä½ãè¯ãæ¹æ³ã¯ãªããã®ãï¼å³æ¸é¤¨ããåãã¦ããPerlã¯ãã¯ããã¯ãéãã¦ã¿ãï¼
my %new_hash = (%hash1, %hash2); # ããã¯ï¼ä»¥ä¸ã®ãããªããã·ã¥ã®åæåãã§ãããã¨ããç´å¾ã§ãã # my %hash = (hoge => 1, bar => 2, piyo =>3); # my %hash = (hoge, 1, bar, 2, piyo, 3);
ããï¼ããããã¦ï¼
my %hash = ('hoge', 1, 'bar', 2, 'piyo', 3); foreach my $keyorvalue (%hash){ print $keyorvalue . "\n" } åºåçµæï¼ bar 3 foo 2 hoge 1
ãããããã¨ãï¼ããã·ã¥ã¯ã¤ã¾ãï¼key, valueã®ãªã¹ãã¨ãã¦ãæ±ããçºè¦ï¼ããã¯ï¼ããªã便å©ãªä½¿ãæ¹ãã§ãããã ï¼
横éã«ããã¦ãã¾ã£ããï¼ãã®è¨æ³ã¯ä¾¿å©ã ããã©ï¼éè¤ãããã¼ãããã¨ä¸æ¸ãããã¦ãã¾ãã¨ããåé¡ãããï¼valueãæ°å¤ã®å ´åã¯ï¼æ°ã«ãã
>|perl
foreach my $key (keys %hash2){
$hash1{$key} += $hash2{$key};
}
|