-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathtest-xs.pl
More file actions
36 lines (29 loc) · 789 Bytes
/
test-xs.pl
File metadata and controls
36 lines (29 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;
use File::Slurper 'read_binary';
use Cpanel::JSON::XS 'decode_json';
use Socket;
sub notify {
my $msg = shift;
socket(my $socket, Socket::PF_INET, Socket::SOCK_STREAM, (getprotobyname('tcp'))[2]);
if (connect($socket, Socket::pack_sockaddr_in(9001, Socket::inet_aton('localhost')))) {
print $socket $msg;
}
close($socket);
}
my $bytes = read_binary '/tmp/1.json';
my $pid = $$;
notify("Perl Cpanel::JSON::XS\t${pid}");
my $jobj = decode_json $bytes;
my $coordinates = $jobj->{coordinates};
my $len = @$coordinates;
my $x = my $y = my $z = 0;
foreach my $coord (@$coordinates) {
$x += $coord->{x};
$y += $coord->{y};
$z += $coord->{z};
}
print $x / $len, "\n";
print $y / $len, "\n";
print $z / $len, "\n";
notify("stop");