Perl Hashes

A hash variable starts with %. It stores key-value pairs, and a single value is read with $scores{Ada}, with a $ and curly braces. Adding a key is just assigning to it.

Perl
use strict;
use warnings;

my %scores = (Ada => 91, Grace => 88);
$scores{Linus} = 79;
for my $name (sort keys %scores) {
    print "$name: $scores{$name}\n";
}
Read the full lesson