Perl Pickle Client

Asked by Bill on 2012-03-30

If anyone is interested. I couldn't find one. (apologies if this is not the correct place to post this) I posted the question
here: http://stackoverflow.com/questions/9829539/perl-equivlent-to-this-python-code
I've been testing it and haven't seen any problems so far.

#!/usr/bin/perl
#
use IO::Socket::INET;
use Python::Serialise::Pickle qw();

my($carbon_server) = '127.0.0.1';
my($carbon_port) = 2004;

my($data) = [
             ["path.mytest", [1332444075,27893687]],
             ["path.mytest", [1332444076,938.435]],
            ];

my($message) = pack("N/a*", pickle_dumps($data));

my($sock) = IO::Socket::INET->new (
                PeerAddr => $carbon_server,
                PeerPort => $carbon_port,
                Proto => 'tcp'
            );
            die "Unable to connect: $!\n" unless ($sock->connected);

$sock->send($message);
$sock->shutdown(2);

# Work around P::S::Pickle 0.01's extremely limiting interface.
sub pickle_dumps {
   open(my $fh, '>', \my $s) or die $!;
   my $pickle = bless({ _fh => $fh }, 'Python::Serialise::Pickle');
   $pickle->dump($_[0]);
   $pickle->close();
   return $s;
}

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
Bill
Solved:
2012-03-30
Last query:
2012-03-30
Last reply:
Bill (bnyec) said : #1

hope someone find it usefull.

This is incredibly useful. Thank you, Bill.

Michael Leinartas (mleinartas) said : #3

Really cool, I've added this to contrib/ in the source tree so that it can be easily found