in reply to How to reference a nested anonymous array

One helpful way to think of this problem may be to replace the cumbersome expression
$fileinfo{$md5hash}{path}
with a simpler, single scalar. That's what that big ugly thing holds after all, a scalar reference to an anonymous array structure. Something like
$aref=\@{$fileinfo{$md5hash}{path}}
would do the trick. Then you can use this scalar reference to your anonymous array like this:
$aref->[0] $#$aref for $x (@$aref) {...}
and so on.
This can be a handy technique sytactically, but also because it reminds you as the programmer what is really stored in those fancy complex data structures like the one you're using. They're just collections of scalar references to other collections, and as such can be passed around as an atomic piece of information. Of course, the correct DE-reference is crucial, but as you can see from above, you can just think of the expression "$aref" as another way of saying "that anonymous array over there". Then things like "$#$aref" (or $#{$aref} if you like) are not so alien.
Good luck with your data mining. Now just for fun, try adding time-lapse views of your filesystem to this structure :)
Paul

Replies are listed 'Best First'.
Re: Re: How to reference a nested anonymous array
by dmmiller2k (Chaplain) on May 29, 2002 at 05:19 UTC

    Note that

    $aref=\@{$fileinfo{$md5hash}{path}}

    dereferences the array and then creates another reference to it. Preferable might be:

    $aref=$fileinfo{$md5hash}{path}

    i.e., don't dereference the array at all, just assign its reference to a scalar for simplicity, readability and maintainability.

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime