I take this to mean that storing hashes in Perl is supported; however
when I tried the following code to store and retrieve a hash in memcached:
>>>
#!/usr/bin/perl
use Cache::Memcached;
# Configure the memcached server
my $cache = new Cache::Memcached {
'servers' => [
'localhost:11211',
],
};
my %testhash;
$testhash{'a'} = 'b';
$testhash{'c'} = 'q';
$cache->set('abc',%testhash);
my %returnedhash = $cache->get('abc');
print $returnedhash{'a'};
>>>
I get the following error:
Argument "q" isn't numeric in int at
/usr/lib/perl5/vendor_perl/5.8.8/Cache/Memcached.pm line 477.
('q' appears in the line "$testhash{'c'} = 'q';". If I replace that
'q' with some other letter, then the error message complains about
whatever letter I put there instead.)
So does this mean that (a) storing Perl hashes in memcached is not
supported after all; (b) it is officially supported, and this is a
bug, or (c) I am doing it wrong?
-Bennett
do not use hash, use hashref instead.
>>>
#!/usr/bin/perl
use Cache::Memcached;
# Configure the memcached server
my $cache = new Cache::Memcached {
'servers' => [
'localhost:11211',
],
};
my %testhash;
$testhash{'a'} = 'b';
$testhash{'c'} = 'q';
$cache->set('abc', \%testhash); # make hashref
my %returnedhash = %{$cache->get('abc')}; # dereference
print $returnedhash{'a'}, "\n";