John Deighan wrote, on Fri 3/11/2005 09:14
: I would like to use DBI handles as hash keys. I thought that I'd read
: somewhere quite a while ago that Perl was adding the capability to use
: non-scalar values as a hash key. However, when I try $h->{$db} = $string,
: where $db is a DBI handle, the DBI handle is converted to a string. If
: that's the way it works, I'm wondering if that's a safe thing to do - i.e.
: if I later do another $h->{$db} = $string2, where $db is the same DBI
: handle, can I be certain that $string2 will replace $string in the same
: hash slot created earlier?
: I would like to use DBI handles as hash keys. I thought that I'd read
: somewhere quite a while ago that Perl was adding the capability to use
: non-scalar values as a hash key. However, when I try $h->{$db} = $string,
: where $db is a DBI handle, the DBI handle is converted to a string. If
: that's the way it works, I'm wondering if that's a safe thing to do - i.e.
: if I later do another $h->{$db} = $string2, where $db is the same DBI
: handle, can I be certain that $string2 will replace $string in the same
: hash slot created earlier?
I think you're really
asking, when I look up $h->{$db} later, will I get $string2? The answer to
that is, "yes."
The other question is whether you
want to be able to iterate over your handles and use them: foreach $handle (keys
%$h). The short answer is, "no," the stringified version that is the key is no
longer a handle per se. However, if your value is not just a string, but an
anonymous list containing both the string and the handle, it works
fine:
$h->{$db} = [$db,
$string];
..
foreach $handle_ref (values
%$h) {
#
$handle_ref->[0] is the handle
#
$handle_ref->[1] is the string
}
Good luck,
Joe
==============================================================
Joseph P. Discenza, Sr. Programmer/Analyst
mailto:[EMAIL PROTECTED]
Carleton Inc. http://www.carletoninc.com
574.243.6040 ext. 300 fax: 574.243.6060
Providing Financial Solutions and Compliance for over 30 Years
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs