On Monday, Nov 17, 2003, at 08:48 US/Pacific, Kent, Mr. John wrote: [..]

For example my(%HASH); $HASH{$sub1}{$sub2}{$sub3} = $file1; $HASH{$sub1}{$sub2}{$sub3}{$sub4}{$sub5} = $file2;

Here is what I tried, unsuccessfully

no strict 'refs'

# @TERMS is an array of each sub-directory name up to the one containing the target file

my(%NAV_HASH);
[..]

$$hash_string is NOT a hash. <-- Herein lies the problem as Billy Zardell would say

quite right, you had declared it to be a static string:

my($hash_string) = "NAV_HASH";

whereas

my $hash = {};

would have been a reference to a hash...

and you really do NOT want to be playing any of the
"dynamic variables" gambiting that would lead that way.

You might want to think about a slightly more complex
data structure to help you deal with your problem, if
I even get your problem... so let me see if I can
write out the file system layout that would wind up
in your hash

        /sub1/sub2/sub3/file1.html
        /sub1/sub2/sub3/sub4/sub5/file2.html

What I am trying to figure out is what the data
is 'suppose to be' at say

$hash->{'sub1'}

What I expect you were seeing with

print "hash_string = $hash_string\n" if ($DEBUG == 1); # <- This looks good

would be something like

NAV_HASH{sub1}{sub2}{sub3}

So while I am sooooo not sure that I get why you want
to do this tree traversal this way, what if you tried
something like,

        #!/usr/bin/perl -w
        use strict;
        use Data::Dumper;
        # #FILENAME# - is for
        
        my $file_1 = '/sub1/sub2/sub3/file1.html';
        my $file_2 = '/sub1/sub2/sub3/sub4/sub5/file2.html';
        my $ref = {};
        hang_sub($ref, $file_1);
        hang_sub($ref, $file_2);
        print Dumper($ref);
        
        #------------------------
        #
        sub hang_sub
        {
                my ($hash, $file ) = @_;
        
                my $next = $hash;
                my $parent;
                my @TERMS =  split('/', $file);
                my $target = pop @TERMS;
                
                my $sub_dir;
                foreach $sub_dir (@TERMS) {
                        $next->{$sub_dir} ={}
                                unless(exists($next->{$sub_dir}));
                        
                        $parent = $next->{$sub_dir};
                        $next = $next->{$sub_dir};
                }
                
                my $key = keys %$parent;
                $parent->{'file'} = $target;
                
        } # end of hang_sub

Data::Dumper can be your friend....

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to