I'm trying to go through an array with a loop, test each element, and eliminate it from said array if it meets a certain condition. I'm using splice with a C-style for loop. However, the array always ends up empty (the array has 2 elements and should only be throwing out one). P.S. - the array is an array of array references.
my $i; for ($i = 0; $i < @un; $i++) { my $username = $un[$i]; my @username = @$username; $sth->execute($username[0]) or die $dbh->errstr; $uid = $sth->fetchrow_array; unless ($uid) { warn "User $username[0] missing.\n"; # remove element from array splice (@un, $i, 1); next; } $info{$uid} = $role; }
Is this because you can't splice an array while iterating over it in a loop? Other problem? Any thoughts appreciated.
Thanks,
AEB
In reply to How do I remove an element from any array while iterating over it in a loop? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |