James Marks wrote: > Down, near the bottom of this example code (marked), I'm trying to count > the number of elements of an array which is the value of a key in a hash > which is, itself, an element of an array. So far, I've been unsuccessful > and I'm stumped as to what to try next. > > Help? > > my @web_sites_directory_tree = > > ( > { > title => 'Web Site One', > directory => 'web_site_one', > subdirectory => [ > 'subdirectory_1', > 'subdirectory_2', > 'subdirectory_3', > 'subdirectory_4', > 'subdirectory_5', > 'subdirectory_6' > ] > }, > { > title => 'Web Site Two', > directory => 'web_site_two', > subdirectory => [ > 'subdirectory_1', > 'subdirectory_2', > 'subdirectory_3' > ] > }, > etc... > ) > > # COUNT NUMBER OF DIRECTORIES - (THIS WORKS) > $directory_count = @web_sites_directory_tree; > > for (my $i = 0; $i < $directory_count; $i++) { > > my $title = "$web_sites_directory_tree[$i]{title}"; > my $directory = "$web_sites_directory_tree[$i]{directory}"; > > # COUNT NUMBER OF SUBDIRECTORIES IN DIRECTORY $i - (THIS DOESN'T WORK) > $subdirectory_count = $web_sites_directory_tree[$i]{subdirectory}; > > # (CONSEQUENTLY, THE REST OF THIS FAILS) > for (my $i = 0; $j < $subdirectory_count; $i++) { > > my $subdirectory = $web_sites_directory_tree[$i]{subdirectory}[$j]; > > print "$title\n"; > print "$directory\n"; > print "$subdirectory\n"; > > } > > } > > Thanks for any help you can provide.
It looks like you want: for my $web_site ( @web_sites_directory_tree ) { for my $subdirectory ( @{ $web_site->{subdirectory} } ) { print "$web_site->{title}\n", "$web_site->{directory}\n", "$subdirectory\n"; } } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>