On Aug 9, 2006, at 12:33 AM, 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?

Oops. I accidentally typed $i instead of $j in second for loop in previous example. This is more correcter:

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 $j = 0; $j < $subdirectory_count; $j++) {

my $subdirectory = $web_sites_directory_tree[$i]{subdirectory}[$j];

        print "$title\n";
        print "$directory\n";
        print "$subdirectory\n";

    }

}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to