Thread IO::Socket::SIPC: Neu (16 answers)
Opened by bloonix at 2007-06-28 01:47

bloonix
 2007-06-28 18:40
#39158 #39158
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Wie wäre es mit sowas?

Code (perl): (dl )
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 Data::Dumper;
use Digest::MD5 qw/md5_hex/;
use Storable;
use POSIX qw/mkfifo/;

my $fifo = int(rand(999999999));
mkfifo($fifo, 0600) or die $!; 

my $md5 = Digest::MD5->new();
my $string = 'Hello World!';

if (fork) {
   my $freezed_data = Storable::nfreeze(\$string);
   my $md5_hex_sum  = md5_hex($freezed_data);
   my $data_packet  = pack("N/a*", $freezed_data);
   open my $fh, '>>', $fifo or die $!; 
   print $fh $md5_hex_sum, $data_packet or die $!; 
   close $fh;
   exit;
}

open my $fh, '<', $fifo or die $!; 
32 == read($fh, my $md5_buf_sum, 32) or die;
4 == read($fh, my $buffer, 4) or die;
my $length = unpack("N", $buffer);
$length == read($fh, my $freezed_data, $length) or die;
close $fh or die;
unlink($fifo) or die;
my $md5_hex_sum = md5_hex($freezed_data);
$md5_buf_sum eq $md5_hex_sum or die;
print "MD5 $md5_buf_sum\n";
print "MD5 $md5_hex_sum\n";
my $ref = Storable::thaw($freezed_data);
print Dumper($ref);


Oder die md5sum nochmal packen?
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread IO::Socket::SIPC: Neu