first, i'll explain a little bit about references:
they *refer* to a (anonymous) data structure, and the need thing about
them is that they behave like scalars when passed around and such.
another thing you have to understand that if you want a hash of hashes,
that is not possible:
perl keeps it's data as flat data structures and hence wouldnt be able
to tell where one list (array/hash) would end and the other would start
this is the same problem you have when passing 2 arrays to a subroutine;
they will become one array.
what you would want is the following:
either just use $self as the container for whatever is in %myflds;
my $self = \%myflds
or set the contents of $self explicitely:
my $self = {
foo => 'bar',
bar => 'quux',
};
i refer you to 2 tutorials i wrote on that subject, which can be found
here:
http://www.sharemation.com/~perl/tut
you will want to read the first tutorial (data structures) and the third
one (references)
i think they will clear up most of the confusion.
hope this helps,
Jos Boumans
Ela Jarecka wrote:
> Unfortunately, it doesn't seem to work... :-(
>
> My constructor:
>
> sub new {
> my $that = shift;
> my $class = ref($that) || $that;
> my $self = {
> %myflds,
> };
> bless $self, $class;
> return $self;
> }
>
> Please help,
> Ela
>
> > -----Ursprüngliche Nachricht-----
> > Von: Jos Boumans [mailto:[EMAIL PROTECTED]]
> > Gesendet: Montag, 11. Juni 2001 12:04
> > An: Ela Jarecka
> > Cc: Beginners list (E-Mail)
> > Betreff: Re: Getting to the contents of a class..
> >
> >
> > What myflds probably is (if used a 'normal' contructor
> > returning a hashref), is
> > a hashref
> >
> > if you want to acces it, you'll need something like:
> >
> > foreach my $item ( keys %{$reqrec->myflds} ) { ..}
> >
> > now, if that is not working, you might want to concider
> > posting the constructor
> > of your module to the list, it would make it easier for us to
> > indicate the
> > problem
> >
> > hth,
> >
> > Jos Boumans
> >
> > Ela Jarecka wrote:
> >
> > >
> > > foreach my $item ( keys $reqrec->myflds ) { #line 26
> > > ...
> > > }
> > >
> > > I get an error:
> > > 'Can't locate object method "myflds" via package "DataReq"
> > at makeReq line
> > > 26'
> > >
> > > How should I indicate that 'myflds' is a hash? I've tried
> > putting an '%' in
> > > front of 'myflds' but it returned
> > > an error as well.
> >