* Klaus Jantzen <[EMAIL PROTECTED]> [2006-02-24T16:09:10] > After the DB-connect I would like to automatically generate the name of the > appropriate set-method in order to reduce the typing :) :
I believe that you meant that while the methods already exist, you just want to
call the methods by generated name -- right? Your example bears this out:
> while (my $hrRes = $sth->fetchrow_hashref)
> {
> foreach (@fields)
> {
> $self->"set".$_($hrRes->{$_});
> # resulting in e.g. $self->setDate($hrRes->{'Date'}) or
> # $self->setAmount($hrRes->{'Amount'})
> }
> }
You can call methods by generated name, but you must put the name in a scalar
first. You can't say:
my $value = $object->"method" . "_etc";
You can say:
my $method_name = "method" . "_etc";
my $value = $object->$method_name;
Does that clear this up?
--
rjbs
pgp1m5oOcSJd4.pgp
Description: PGP signature
