for($x=0; $x<$sth->rows; $x++) {
$data = $sth->fetch_hashref;
$this = $data->{id};
$prev = ...
}
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;
};
$prev =; for (......) { $data = ; $element = ; ... process data allowing for dummy value in $prev ... $prev = $element; }
perlmonks.org content © perlmonks.org and Anonymous Monk, blazar, Corion, tweetiepooh
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03