Trying to print fruits followed by their colors using a for loop.
use strict;
my %colors = ( apple => 'red',
orange => 'orange',
watermelon => 'green',
grapes => 'blue',
rest => 'pink' );
for (keys %colors) {
print("color of $_ is $colors($_)\n");
}
CodePudding user response:
$colors($_)
must be $colors{$_}
Accessing hash values requires the use of { }