RuneK has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have two stucts (Class::Struct) that looks like this:
struct directory => { name => '$', files => '@', }; struct file => { name => '$', permis => '$', };
I want to add all the files of a directory into the directory struct which is no problem, but I don't know how to access the data afterwards. The following does not work:
#@direc contains a list of directories foreach $dir (@direc){ foreach $fi (@{$dir->files}){ print $dir->$fi->name; } }
The error I get is: Can't locate object method "task=HASH(0x400a76fc)" via package "folder" at ... So I guess the error is reference related. Anyone to give a hand? Thanks in advance, Rune P.S. Whether to use a struct or not is not up for discussion :) - Not my choice

Replies are listed 'Best First'.
Re: How to access struct of structs
by borisz (Canon) on Aug 11, 2004 at 12:18 UTC
    just a guess, but I think you want:
    print $dir->name . '/' . $fi->name;
    instead of print $dir->$fi->name;
    Boris
Re: How to access struct of structs
by reneeb (Chaplain) on Aug 11, 2004 at 12:31 UTC
    I think you need to use the curly brackets. try:
    foreach $dir (@direc){ foreach $fi (@{$dir->{files}}){ print $dir.'/'.$fi->{name}; } }