http://qs1969.pair.com?node_id=451838

tcf03 has asked for the wisdom of the Perl Monks concerning the following question:

I threw together the following code while reviewing perldsc and perlref.
#!/usr/bin/perl -w #use strict; my %family = ( 'parents' => ['Barbie', 'Ken'], 'siblings' => ['John', 'Robert'], 'wife' => ["Heather"], 'pets' => ["Miles", "Vanilla", ["Dallas", "some cat +"], ["snoopy", "woodstock"] ], 'inlaws' => [ ["Luke", "Leigh"], ["Carol", "Jack"] ], 'sisinlaw' => ["Lucy"], 'broinlaw' => ["Linus", "Pig Pen"], 'friends' => ["Jack", "Jill", "Peter", "Mac"], 'coworkers'=> ["sammy", "colin", "dave"] ); for my $label ( sort keys(%family) ) { my @names = $family{$label}; print "$label\n"; for my $name ( 0 .. $#names ) { for my $names ( 0 .. $#{ $family{$label} } ) { print "\t$family{$label}->[$names]\n"; for my $x ( 0 .. $#{ $family{$label}->[$names] } ) { print "\t$family{$label}->[$names][$x]\n "; #this is where Im stuck. Id like to # just print out the names in the # arrays } } } }
and it does what I want. Wellllll, almost. Plus I cant use strict; My output looks like this:
broinlaw
	Linus
	Pig Pen
coworkers
	sammy
	colin
	dave
friends
	Jack
	Jill
	Peter
	Mac
inlaws
	ARRAY(0x8069d88)
	Luke
 	Leigh
 	ARRAY(0x8069db8)
	Carol
 	Jack
 parents
	Barbie
	Ken
pets
	Miles
	Vanilla
	ARRAY(0x8069ce0)
	Dallas
 	some cat
 	ARRAY(0x8069d10)
	snoopy
 	woodstock
 siblings
	John
	Robert
sisinlaw
	Lucy
wife
	Heather
if I  use strict; the following code must be removed
for my $x ( 0 .. $#{ $family{$label}->[$names] } ) { print "\t$family{$label}->[$names][$x]\n "; }
and Ill get this output
broinlaw
	Linus
	Pig Pen
friends
	Jack
	Jill
	Peter
	Mac
inlaws
	ARRAY(0x806a030)
	ARRAY(0x806a060)
parents
	Barbie
	Ken
pets
	Miles
	Vanilla
	ARRAY(0x8069fc4)
siblings
	John
	Robert
sisinlaw
	Lucy
wife
	Heather
Which is obviously not my intention either. Any pointers to some help would be greatly appreciated.


Ted

--
"Men have become the tools of their tools."
  --Henry David Thoreau