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.
if I use strict; the following code must be removed
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
and it does what I want. Wellllll, almost. Plus I cant use strict; My output looks like this:#!/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 } } } }
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
and Ill get this outputfor my $x ( 0 .. $#{ $family{$label}->[$names] } ) { print "\t$family{$label}->[$names][$x]\n "; }
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
Ted
--
"Men have become the tools of their tools."
--Henry David Thoreau
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: iterating a hash of (complex?) arrays
by ikegami (Patriarch) on Apr 27, 2005 at 03:53 UTC | |
Re: iterating a hash of (complex?) arrays
by Roy Johnson (Monsignor) on Apr 27, 2005 at 03:56 UTC | |
by tcf03 (Deacon) on Apr 27, 2005 at 04:02 UTC | |
Re: iterating a hash of (complex?) arrays
by tcf03 (Deacon) on Apr 27, 2005 at 03:39 UTC | |
by ikegami (Patriarch) on Apr 27, 2005 at 03:44 UTC |
Back to
Seekers of Perl Wisdom