tame1 has asked for the wisdom of the Perl Monks concerning the following question:

I am currently working on a script which involves some RSA encryption, as well as MD5 work.

Here is the troublesome subroutine:
sub get_pubkey { my $issuer = shift; my %hash; tie %hash, 'BerkeleyDB::Hash', -Filename => "/home/httpd/newkeyrin +g" or die "Cannot tie the hash to that file: $! $BerkeleyDB::Error\n" +; open(TEST, ">> fields_data"); foreach my $hashkey (keys %hash) { print TEST "The pubkey is: $hashkey\n"; print TEST "The value is: $hash{$hashkey}\n"; print "The pubkey is: $hashkey<br>\n"; print "The value is: $hash{$hashkey}<br>\n"; } my $server = "$issuer" . ".PUBLIC"; my $val = $hash{$server}; close(TEST); untie %hash; print "Server is : $server<br>\n"; print "Public key currently is: $val<br>\n"; return $val; }
Everything seems fine (It all prints out - %hash only contains 2 keys and 2 values) until the final print of the Public Key - THAT comes up blank. $server is set fine, but $val is empty. The sub also returns nada. Can anyone see what I am doing wrong to cause this?

What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

Replies are listed 'Best First'.
Re: Strange problems with Tie
by clintp (Curate) on Mar 26, 2001 at 21:43 UTC
    open(TEST, ">> fields_data");
    *grumble* Always check the rsult of system calls...moving on.

    The keys in the hash are not what you think they are. If print "$foo{$key}" says one thing, but later on $key="X", $val=$foo{$key} says another, then you're $key's aren't the same in both places. Simple as that. (or the DBM is whacked.)

    In your diagnostics, put some quotemarks around the keys as you print them. Check for unprintables too.

(Ovid) Re: Strange problems with Tie
by Ovid (Cardinal) on Mar 26, 2001 at 21:39 UTC
    I can't see anything wrong with your code. Dumb question time: is one of the $hashkeys that you print in the foreach loop and exact duplicate of "$issuer" . ".PUBLIC"? If not, you'll autovivify the hash entry, which I am guessing will be written to the file, but of course have no value. As a result, you'll have nothing in $val.

    Show us your output. What's in $issuer? We'll need to see that to really give good feedback.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Strange problems with Tie
by tame1 (Pilgrim) on Mar 26, 2001 at 22:04 UTC
    ***BLUSH***

    Turns out there was a non-printing character difference in the keys.



    What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"