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
|