Perhaps I wasn't supposed to take it so literally, and my hash handling
skillz aren't quite what they should be.

When I do this:

while (my $hashref = $csr->fetchrow_hashref())
{
  print "Adding record from group " . $hashref->{group_code} . ".\n";
  push (@{$groups{$hashref->{group_code}}}, $hashref);
}

($csr is my $sth var)

The print statement prints nothing for the $hashref->{group_code}
reference.  This seems to be an indication of the start of a domino effect
of things not being seen.

What am I doing wrong?

Don.

On Thu, 1 Nov 2001, David Marshall wrote:

> I'll second the suggestion made a few messages back about storing your
> results in some other data structure (as opposed to re-traversing the data
> structure that DBI gives you).
>
> In your circumstances, I'd probably put the retrieved rows in a hash of
> arrays (keyed by group number) before doing anything else.  Then I'd
> examine each array of records in the group and delete it from the hash if
> it didn't qualify.  Then the HoA that is left over can be traversed for
> whatever the final output is.
>
> The code might look something like this:
>
> my %groups;
> while (my $hashref = $sth->fetchrow_hashref) {
>     push @{$groups{$hashref->{group_num}}}, $hashref;
> }
>
> then later...
>
> foreach my $group_number (keys %groups) {
>     delete $groups{$group_number} unless group_is_OK($groups{$group_number});
> }
>
> then finally...
>
> spew_group($_) foreach values %groups;
>
> YMMV on exact implementation.  In similar implementations, I will often
> have other stuff in the data structure beyond that which I got directly out
> of the database.  It all depends.
>
> At 01:26 PM 11/1/01 -0600, Don Seiler wrote:
> >Perhaps I'm missing it, then.
> >
> >basically my query is this:
> >
> >select cust_no, acct_type, acct_status, group_num
> >from cust,acct
> >where cust.cust_no=acct.cust_no
> >order by group_num
> >
> >the values of acct_type and acct_status for all of the records in
> >a group determine if I want that group or not.  I don't think I can make
> >that determination until I've gone through the recordset though.
> >
> >--
> >Don Seiler             [EMAIL PROTECTED]
> >Database Administrator / Sr Software Engineer
> >NSightTel Billing LLC    Phone:  920.617.7501
> >1580 Mid Valley Drive    Fax:    920.617.7493
> >De Pere, WI  54115       Cell:   920.606.3240
> >Pager: [EMAIL PROTECTED] / 920.613.2000
> >
> >
> >On Thu, 1 Nov 2001, Marcelo Guelfi wrote:
> >
> > >
> > > Are you sure that you can't use the GROUP BY clause?
> > >
> > > Saludos,
> > >                   Marcelo.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >                     "Don Seiler"
> > >                     <Don.Seiler@Ce       To:     Michael Peppler
> > <[EMAIL PROTECTED]>
> > >                     llcom.com>           cc:     Marcelo
> > Guelfi/Uruguay/Contr/IBM@IBMUY, <[EMAIL PROTECTED]>
> > >                                          Subject:     Re: Looping
> > through recordset twice
> > >                     01/11/2001
> > >                     16:13
> > >                     Please respond
> > >                     to "Don
> > >                     Seiler"
> > >
> > >
> > >
> > >
> > >
> > > Basically, when I get to a new group number.  The record set is ordered by
> > > group number, so all records in a group are together.  As I'm looping
> > > through records in a group, I do some evaluation and add values to
> > > variables.  When I get to a new group number, I look at the values.  If
> > > they meet my criteria I add the last group number to an array.
> > >
> > > Then when I'm done I planned to loop again through the record set and if
> > > the group number matches one in the array I'd print it.
> > >
> > > This is probably horribly inefficient and I'm leaning towards saving the
> > > records to a tmp array and if they qualify saving that to master array for
> > > later printing.
> > >
> > > Don.
> > >
> > > On Thu, 1 Nov 2001, Michael Peppler wrote:
> > >
> > > > Don Seiler writes:
> > > >  > Actually the nature of the problem is what stopped me from doing this.
> > > >  >
> > > >  > I won't know which records I want until I look at the group of them.
> > > >  >
> > > >  > Example:  I have a table of records.  There is a "groupnum" column.
> > > Many
> > > >  > records have the same "groupnum", i.e. they are in the same group.
> > > I'm
> > > >  > only interested in selecting the group as a whole.  I will only know
> > > if I
> > > >  > want this group based on examining all of the records for that group.
> > > >
> > > > Hmmm - what condition determins that a group is complete?
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
>
>

Reply via email to