>> > I have created a module, and inside one of the Package methods, I >> have >> > the following code: >> > >> > $href = $getPlanInfo->fetchrow_hashref(); >> > foreach my $key (keys %$href) { >> > print "$key : $href->{$key}\n"; >> > $name = $key; >> > $self->{$name} = $href->{$key}; >> > } > > So in the above you want to loop over the result set storing them to > the > object, this sounds like the perfect use of an array reference stored > to > the object. Something like: > > while (my $href = $getPlanInfo->fetchrow_hashref) { > push @{$self->{$name}}, $href; > } > > Now $self->{$name} contains a list, similar to what you mention with > the > indexes below, but let Perl handle that for you. Then you can loop > over > the list as with any array reference, or index into it similar to any > array. > > foreach my $element (@{$self->{$name}}) { > foreach my $key (keys %$element) { > print "$key: $element->{$name}\n"; > } > }
Wow! ...and I *almost* understand how it works! Admittedly, I'm just begun familiarizing myself with references the last few days, but this looks so far like what I need. I am going to research how, and why this works, but am I correct with this?: (based on your code above, assuming 2 rows in db for user) @{$self->{$name}}[0] == %hash (name & val) # from db row 1 @{$self->{$name}}[1] == %hash2 (name & val) # from db row 2 I truly was never aware the true flexibility of Perl before. Wow...if I had of researched this stuff before...I don't want to even imagine the time I would of saved myself ;o) Steve > > HTH, > > http://danconia.org > >> > >> > Now, in the main program that calls this method, I have the >> following: >> > >> > my ($user) = new Accounting::EagleUser(); >> > $user->getPlanInfo("steveb"); >> > print "$user->{'plan'} $user->{'username'}\n"; >> > >> > >> > What is happening, is that getPlanInfo() takes a single param, (a >> > username). It then performs a fetchrow_hashref, creating the keys >> for >> > the user object with the table field names from the db, and the >> values >> > are the actual data from the table row. >> > >> > However, my problem is that some users have more than one row. I >> have >> > tried for days, playing, reading, etc and you guys(gals) feel like >> my >> > last hope. I can't figure out a way to give the user object >> multiple >> > values for a single key. The output when print only shows the >> fetched >> > row that it got first, and it appears the second is never looked >> at. >> > >> > I was thinking that if I implemented something like >> $self->{$key$i}, >> > where $i could be an incremented integer, I'd have what I was >> looking >> > for, but how do I iterate through the DB to the next row using >> > fetchrow_hashref to do this? >> > >> > I really appreciate any insight at all that will help clarify this >> for >> > me, or at least put me back on a path I feel I have wandered waaay >> off >> > of. >> > >> > Tks! >> > >> > Steve >> > >> > >> > >> > -- >> > To unsubscribe, e-mail: [EMAIL PROTECTED] >> > For additional commands, e-mail: [EMAIL PROTECTED] >> > <http://learn.perl.org/> <http://learn.perl.org/first-response> >> > >> > >> > >> >> >> -- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> <http://learn.perl.org/> <http://learn.perl.org/first-response> >> >> >> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>