in reply to Trying to pull the key values from a Hash
#OUTPUT:#!/usr/local/bin/perl use strict; use warnings; my %children; #each parent has 3 children identified by their IDs $children{'parent1'}{'a'}{'id'} = 'Child1P1'; $children{'parent1'}{'b'}{'id'} = 'Child2P1'; $children{'parent1'}{'c'}{'id'} = 'Child3P1'; $children{'parent2'}{'a'}{'id'} = 'Child1P2'; $children{'parent2'}{'b'}{'id'} = 'Child2P2'; $children{'parent2'}{'c'}{'id'} = 'Child3P2'; for my $parent (sort keys (%children)){ print "The key value is a reference of type: ", ref $children{$par +ent}, $/; print "The parent is $parent:\n"; for my $child (keys (%{$children{$parent}})){ print "children of $parent-> $children{$parent}{$child}{'id +'}\n"; } print "\n\n"; }
The key value is a reference of type: HASH The parent is parent1: children of parent1-> Child3P1 children of parent1-> Child1P1 children of parent1-> Child2P1 The key value is a reference of type: HASH The parent is parent2: children of parent2-> Child3P2 children of parent2-> Child1P2 children of parent2-> Child2P2
|
|---|