in reply to Remember previous element in a loop
Simply remember your "previous" element before you fetch the next element.
my $data; for($x=0; $x<$sth->rows; $x++) { my $prev = $data; $data = $sth->fetch_hashref; my $this = $data->{id}; }
Maybe you should use a different loop style than the C loop for iterating over your results to avoid the polling of $sth->rows:
my $prev; while (defined my $data = $sth->fetchrow_hashref) { my $this = $data->{id}; ... $prev = $data; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Remember previous element in a loop
by Anonymous Monk on Feb 03, 2006 at 11:46 UTC |