[Pdx-pm] Hash question

Joe Oppegaard joe at radiojoe.org
Fri Nov 21 17:45:55 CST 2003


On Fri, 21 Nov 2003, Roderick A. Anderson wrote:

> New to the list and glad I found it.  Not from the Portland area (Hayden,
> ID).
>

Cool, welcome to the list.

> First the append hash solution.  I use the hash generated from some CGI.pm
> params then query a SQL Server database and and use DataHash to returned
> the row.  To append to the original hash I'm using a variation on code I
> got out of "Perl Cookbook".
>
> 	%SignUpInfo = (%SignUpInfo, $db2->DataHash());
>
> Is there a better or more efficient way to do this?
>
>
> Then the Win32::ODBC issue.  When I use the above $db2->DataHash() whether
> appending or creating a new hash I end up with an empty key/value in
> the hash.
>
> Doing a
>
>         foreach my $key (sort keys %SignUpInfo) {
>             print "$key: $SignUpInfo{$key}\n";
>
> gets me output with one line with only the colon on it.  Is there a way to
> remove this key/value combination?  I think it has to do with Win32::ODBC
> returning some kind of row identifier.
>

I'm guessing that %SignUpInfo was initially empty up top and
$db2->DataHash() had some type of error condition and returned undef
or ''.

Take the following for example which will print just a colon:

----------
sub ret_undef {
    return undef;
}

%a = ret_undef();
foreach (keys %a) {
    print "$_ : $a{$_}\n";
}
----------

Or to get a better idea of what's in the hash:

use Data::Dumper;
print Dumper(\%a);

Which shows you that you actually do have a blank key:
$VAR1 = {
          '' => undef
        };

I don't think you really want to remove the blank key/value combination,
you probably just want to make sure you're properly checking for error
conditions when doing the Win32::ODBC calls.

	-Joe Oppegaard



More information about the Pdx-pm-list mailing list