Re: Tie hashes in DBIx::Recordset [OT]
Hi there, On Wed, 13 Mar 2002, Marcus Claesson wrote: How do I succesfully preserve the column order (''$fields'= $joined_col') in my array-of-hashes generated using DBIx::Recordset? Check out a Perl tutorial or the Camel book. Perl's hashes do their own thing with ordering, so unless you do something like (sort keys %hash) you will get what you get. Arrays can preserve sequences but involve you in more coding much of the time. 73, Ged.
Re: Tie hashes in DBIx::Recordset [OT]
Perl's hashes do their own thing with ordering, so unless you do something like (sort keys %hash) you will get what you get. Yes, but tieing the hash while creating it, in my case with Tie::IxHash, should preserve the inesertion order. That works with for example tie %hash, 'Tie::IxHash'; %hash = (one=1, two=2, three=3); But not when I create an array of hashes using DBIx::Recordset like below: use Tie::IxHash; use DBIx::Recordset; ...sub execute { tie %main::set, 'Tie::IxHash'; *main::set = DBIx::Recordset-Search({('!DataSource' = $db, '!Table' = $table, '$fields' = $joined_col, '$where'= $query, '$max' = 10)}); } Marcus Ged Haywood wrote: Hi there, On Wed, 13 Mar 2002, Marcus Claesson wrote: How do I succesfully preserve the column order (''$fields'= $joined_col') in my array-of-hashes generated using DBIx::Recordset? Check out a Perl tutorial or the Camel book. Perl's hashes do their own thing with ordering, so unless you do something like (sort keys %hash) you will get what you get. Arrays can preserve sequences but involve you in more coding much of the time. 73, Ged.
RE: Tie hashes in DBIx::Recordset [OT]
Obviously sorting the hash keys wont give you the columns in the select statement order. After doing something like: my $sth = $dbh-execute(@params) or die... You can get back the lower case column names in the select statement order using: my @names = @{$sth-{NAME_lc}}; Note that $sth-{NAME_lc} is not always populated, depending upon your SQL. Regards Jeff -Original Message- From: Ged Haywood [mailto:[EMAIL PROTECTED]] Sent: 13 March 2002 10:30 To: Marcus Claesson Cc: [EMAIL PROTECTED] Subject: Re: Tie hashes in DBIx::Recordset [OT] Hi there, On Wed, 13 Mar 2002, Marcus Claesson wrote: How do I succesfully preserve the column order (''$fields'= $joined_col') in my array-of-hashes generated using DBIx::Recordset? Check out a Perl tutorial or the Camel book. Perl's hashes do their own thing with ordering, so unless you do something like (sort keys %hash) you will get what you get. Arrays can preserve sequences but involve you in more coding much of the time. 73, Ged.