On Mon, Jun 24, 2002 at 08:35:25AM -0700, Roy Rubin wrote:
>Thanks Roger. How would I use the same concept and apply it to fetching
>records from a database, something along the lines below.
Just replace my @inner_loop_data with whatever actually generates the
data. More or less what you have, though you appear to be using package
variables rather than locals - if you're not writing everything under
"use strict", I _highly_ recommend that you do so. More importantly,
your $whatever is undefined - initialise this with a "my" _outside_ the
inner loop. That way you'll get a new variable each time you iterate
over the outer loop. Contrast "my @l2" in my code.
>I am looking to
>use the refernces that are already part of the DBI, instead of hard coding
>the variables (as in $OfficeID, etc.) I hope this makes sense.
Check out fetchrow_hashref in perldoc DBI. You might end up doing
something like:
my @l1;
my $sth=$dbh->prepare("SELECT blah blah ... ");
$sth->execute;
while (my $r=$sth->fetchrow_hashref) {
# manipulate $r if desired, for example by adding an inner loop:
$r->{something_not_in_database}=$something_else;
# once all manipulation is done:
push @l1,$r;
}
For the innermost loop, you could even use fetchall_arrayref (also in
perldoc DBI).
Roger
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]