嘗試使用 for 回圈列印水果及其顏色。
use strict;
my %colors = ( apple => 'red',
orange => 'orange',
watermelon => 'green',
grapes => 'blue',
rest => 'pink' );
for (keys %colors) {
print("color of $_ is $colors($_)\n");
}
uj5u.com熱心網友回復:
$colors($_)一定是$colors{$_}
訪問哈希值需要使用{ }
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443080.html
標籤:perl
