ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-DBI
perl-DBI
RE: hashes
by Sumit Babu other posts by this author
Oct 19 2000 2:49PM messages near this date
hashes | Re: hashes
Hi,

	You can use the fetchrow_hashref() method to get the result in a directly
to a hash reference. This method fetches the next row of data and returns it
as a reference to a hash containing field name and field value. Please see
the DBI documentation for more details on this.

If speed is what you need, you can also use the hash slice here i.e. you can
do:

@Header = @{$sth-> {NAME_uc}}; # Now you have the field names in @Header.

while ( @Fields = $sth-> fetchrow_array() ) {
	@FieldValues{@Header} = ( @Fields ); # Hash slice.
	# for more info on hash slice see
http://www.sysarch.com/perl/tutorials/hash_slices.txt
	# now you can refer as $FieldValues{'NAME_30'} and $FieldValues{'ACCESS'}
...
}

Regards,

Sumit.

-----Original Message-----
From: dbi-users-bounce@[...].org [mailto:dbi-users-bounce@[...].org]On
Behalf Of Xen
Sent: Thursday, October 19, 2000 2:16 PM
To: DBI Users
Subject: hashes



Hello DBI,

   Anybody know how i can recognize name of column from query or
   (better) get it as hash. Of course results be unique only in one
   column.

   Example:

   SQL - "select name_30, access as Name from users"

   name - unique
   access [1,2,3]

   while(my(%res) = $sec-> fetchrow) {
      %res{'Name'}....
   }

   Big thanks.

- Mikhail Kashkin (Russia)
  Web-master http://xen.al.ru/




----------------------------------------------------------------------------
--
DBI HOME PAGE AND ARCHIVES: http://www.symbolstone.org/technology/perl/DBI/
To unsubscribe from this list, please visit:
http://www.isc.org/dbi-lists.html
If you are without web access, or if you are having trouble with the web
page,
please send mail to dbi-users-request@[...].org with the subject line of:
'unsubscribe'.
----------------------------------------------------------------------------
--



------------------------------------------------------------------------------
DBI HOME PAGE AND ARCHIVES: http://www.symbolstone.org/technology/perl/DBI/
To unsubscribe from this list, please visit: http://www.isc.org/dbi-lists.html
If you are without web access, or if you are having trouble with the web page, 
please send mail to dbi-users-request@[...].org with the subject line of:
'unsubscribe'.
------------------------------------------------------------------------------ 
Thread:
Xen
Sumit Babu
Bodo Eing

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved