10.8. Multi dimensional hashes

Example 10-1. examples/hashes/grades.pl

#!/usr/bin/perl
use strict;
use warnings;

my %grades;
$grades{"Foo Bar"}{Mathematics}   = 97;
$grades{"Foo Bar"}{Literature}    = 67;
$grades{"Peti Bar"}{Literature}   = 88;
$grades{"Peti Bar"}{Mathematics}  = 82;
$grades{"Peti Bar"}{Art}          = 99;

foreach my $name (sort keys %grades) {
    foreach my $subject (keys %{$grades{$name}}) {
        print "$name, $subject: $grades{$name}{$subject}\n";
    }
}

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed