#!/usr/bin/perl print "Hello, World...\n"; use strict; use Data::Dumper; my @in = qw/ fruit:apple:cox fruit:apple:pippin fruit:apple:granny fruit:banana:yellow fruit:banana:green /; #make an anonymous hash my $h = {}; foreach (@in) { my @a = split ':',$_; my $branch = shift @a; my $species = shift @a; my $breed = shift @a; $h->{$branch}->{$species}->{$breed} = $h->{$branch}->{$species}->{$breed} + 1 || 1; } print Dumper($h); print "there are ".scalar (keys %{$h->{fruit}})." fruit species\n"; print "there are ".scalar (keys %{$h->{fruit}->{apple}})." apple breeds\n"; print "there are ".scalar (keys %{$h->{fruit}->{banana}})." banana breeds\n"; print "Good luck with your homework\n";