> my @ids_ary = [];
> my @names_ary = [];
> my @age_ary   = [];

Why do you need an empty arrayref as the first element of these?


>   $name_ary[$i] = $name;
>   $i++;

push @name_ary, $name also works, and makes it more clear that you're
using a parallel arrays data structure.

here's an alternative:

  sub iID(){0} sub iNAME(){1} sub iAGE(){2}
  my @IdNameAge_pary = ( [],[],[] );
  while (my ($id,$name,$age) = @{$sth->fetch}){
     push @{$IdNameAge[iID]},$id;
     push @{$IdNameAge[iNAME]},$name;
     push @{$IdNameAge[iAGE]},$age;
  };
  ...


but seriously, loading everything into a temporary array just uses a
lot of memory and makes the code larger, so I avoid it when I can.
DBI's facility for providing a hashrefs for every result row makes it
easy to use names not numbers, and usually the kinds of processing
that you would need all the results in memory for (sorting, finding a
max or min) can be done with SQL (unless of course there aren't
enough, or the right, indexes.)

Reply via email to