<?xml version="1.0" encoding="windows-1252"?>
<node id="1003899" title="Re: OOP: How to construct multiple instances of a class at once" created="2012-11-14 18:00:13" updated="2012-11-14 18:00:13">
<type id="11">
note</type>
<author id="31503">
runrig</author>
<data>
<field name="doctext">
Here is an incomplete example:&lt;code&gt;
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-&gt;prepare($sql);
  $sth-&gt;execute();
  $sth-&gt;bind_cols(\my ($id, $name));
  while ( $sth-&gt;fetch() ) {
    push @users, bless({
      user_id   =&gt; $id,
      user_name =&gt; $name,
    }, $class);
  };
  return wantarray ? @users : $users[0];
}
&lt;/code&gt;
The @ids should be scrubbed for Bobby Tables issues, but that is also the case in your original code.</field>
<field name="root_node">
1003841</field>
<field name="parent_node">
1003841</field>
</data>
</node>
