in reply to Multidimensional Hash

Assuming you are using DBI, the following template should give you a good starting point:

my %results = (); my $query = qq(SELECT id, col1, col2 FROM some_table); my $sth = $dbh->prepare($query); while (my $rh_row = $sth->fetchrow_hashref) { my $id = delete $rh_row->{id}; $results{$id} = { %$rh_row }; }

Regards,

PN5

Replies are listed 'Best First'.
Re^2: Multidimensional Hash
by rnahi (Curate) on Aug 07, 2004 at 05:21 UTC

    Why reinventing (badly) the wheel?

    my $query = qq(SELECT id, col1, col2 FROM some_table); my $results = $dbh->selectall_hashref($query, 1);

    Read all the explanation in DBI and DBI Recipes.

      • The original question was somewhat vague in terms of requirements
      • I provided a generic template using methods that I knew would be available without knowing the version of DBI in use
      • You are at liberty to dislike my solution
      • Constructive criticism might have been a better approach

      Many Internet Service Providers (ISPs) take the "if it ain't broke, don't fix it" approach. For instance, the ISP I moved from almost a year ago still uses a version of DBI that does not support the selectall_hashref() method.

      Regards,

      PN5