http://www.perlmonks.org?node_id=287828


in reply to Re: Frontier::RPC and Digest::MD5
in thread Frontier::RPC and Digest::MD5

Ok, I wrote some simple code to show this, and managed to narrow the problem down a little. Here is the code:

This is the server:

#!/usr/bin/perl -w use strict; use Frontier::Daemon; use Digest::MD5 qw/md5_hex/; Frontier::Daemon->new (LocalPort => 12345, methods =>{md5=>sub {return md5_hex (shift)}}); __END__

And the client:

#!/usr/bin/perl -w use strict; use Frontier::Client; my $rpc = Frontier::Client->new (url =>"http://localhost:12345/RPC2"); print $rpc->call ("md5", "1234"), $/; __END__

For reference:

md5 of "1234": 81dc9bdb52d04dc20036dbd8313ed055
md5 of "": d41d8cd98f00b204e9800998ecf8427e

Now, here's what I found. If I run the server on my desktop (perl 5.8.0), I get the expected result (81dc..). If I run the server on an older system (perl 5.6.1), I get the erroneous one (d41d..), along with the error on the console:

Use of uninitialized value in subroutine entry at ./srv line 8.

I have also found that even in the older system, the following code works:

sub my_md5_hex { my ($str) = @_; my $cmd = "perl -MDigest::MD5 -e " . "'print Digest::MD5::md5_hex (\"$str\"), \$/'"; my $md5 = `$cmd`; chomp ($md5); return $md5; }

It's pretty gross, though.