Return keys from $db->DataHash directly into an array

Return keys from $db->DataHash directly into an array

am 16.09.2007 17:56:40 von dtshedd

Is there anyway to pass just the keys of a data hash directly into an
array or is it necessary to do something like this?

$db->Sql("SELECT * FROM Groups");
$db->FetchRow();
%hash = $db->DataHash;
foreach $key (keys %hash) {
@fields[$i]=$key;
print "my field $fields[$i]\n";
$i++;

}


TIA

dan

Re: Return keys from $db->DataHash directly into an array

am 16.09.2007 22:37:28 von Mike Pomraning

dtshedd@yahoo.com wrote:
> Is there anyway to pass just the keys of a data hash directly into an
> array or is it necessary to do something like this?

Please identify the name of the module in question (Win32::ODBC, in this
case).

> $db->Sql("SELECT * FROM Groups");
> $db->FetchRow();
> %hash = $db->DataHash;
> foreach $key (keys %hash) {
> @fields[$i]=$key;

Please read perlfaq4, "What is the difference between $array[1] and
@array[1]?"

In any case, this is a data structure question, not a module-specific
question. Try ``@fields = keys %hash'' after you've read the FAQs.

Regards,
Mike