类似的问题(没有解决我的问题):是否有可能检测当前的while循环迭代是否是perl中的最后一个?
上面的帖子有一个答案,它解决了仅在从文件读取时检测它是否是最后一次迭代的问题.
在while循环中,是否可以检测当前迭代是否是mysql查询中的最后一个迭代?
while( my($id, $name, $email) = $sth->fetchrow_array() )
{
if(this_is_last_iteration)
{
print "last iteration";
}
}
Run Code Online (Sandbox Code Playgroud)
my $next_row = $sth->fetch();
while (my $row = $next_row) {
my ($id, $name, $email) = @$row;
$next_row = $sth->fetch();
if (!$next_row) {
print "last iteration";
}
...
}
Run Code Online (Sandbox Code Playgroud)