in reply to
OOP: How to construct multiple instances of a class at once
Here is an incomplete example:
sub new {
my ($class, @ids) = @_;
my @users;
my $sql = "SELECT user_id, user_name FROM users WHERE user_id IN ("
+. join(",", @ids) . ")";
my $sth = $dbh->prepare($sql);
$sth->execute();
$sth->bind_cols(\my ($id, $name));
while ( $sth->fetch() ) {
push @users, bless({
user_id => $id,
user_name => $name,
}, $class);
};
return wantarray ? @users : $users[0];
}
The @ids should be scrubbed for Bobby Tables issues, but that is also the case in your original code.