On Mon, Jun 11, 2001 at 12:24:00PM +0200, 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;
> }
This method works just fine, provided %myflds is at least declared
beforehand (you are using strict, yes?):
test.pl
=======
{
package Class;
my %myflds = qw(foo bar blah doo);
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = { %myflds };
bless $self, $class;
return $self;
}
}
print Class->new(), "\n";
> ./test.pl
Class=HASH(0x4000d220)
Exactly as expected.
> > Ela Jarecka wrote:
> >
> > >
> > > foreach my $item ( keys $reqrec->myflds ) { #line 26
> > > ...
> > > }
If, out of the constructor you showed us above, you're expecting the myflds
method to automatically be created, and return your hash, it's not going to
happen. You have to define a myflds method, probably something along the
lines of:
sub myflds {
my $self = shift;
return $self;
}
>From this point on, you can now refer to %{ $reqrec->myflds }.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--