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
37
38
use strict;
use IO::Socket;
use IO::Socket::INET;
use threads;
my $sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => 6667,
Proto => 'tcp') or
die "Can't connect\n";
my $sock2 = IO::Socket::INET->new(PeerAddr => $server2,
PeerPort => 9999,
Proto => 'tcp') or
die "Can't connect\n";
my $thread1 = Thread->create(&gateway2irc);
$thread1->join();
my $thread2 = Thread->create(&chat2gateway);
$thread2->join();
sub gateway2irc {
while (my $input = <$sock>) {
chomp($input);
if ($input =~ /^PING(.*)$/i) {
print $sock "PONG $1\r\n";
}
}
}
sub chat2gateway {
while (my $input2 = <$sock2>) {
if ($input2 =~ "ping") {
print sock "PRIVMSG $channel : ping\n";
}
}
}
perldoc threads$thr = threads->create(FUNCTION, ARGS)
...
FUNCTION may either be the name of a function, an anonymous subroutine, or a code ref.
my $thr = threads->create(\&func, ...);
1
2
3
4
my $thread1 = threads->create(\&gateway2irc);
$thread1->join();
my $thread2 = threads->create(\&chat2gateway);
$thread2->join();
Guest Paul321Ah ok. Funktioniert aber leider trotzdem nicht
Code: (dl )1
2
3
4my $thread1 = threads->create(\&gateway2irc);
$thread1->join();
my $thread2 = threads->create(\&chat2gateway);
$thread2->join();
1 2 3 4 5
my $thread1 = threads->create(\&gateway2irc); my $thread2 = threads->create(\&chat2gateway); $thread1->join(); $thread2->join();
Quotemy $thr = threads->create('func_name', ...);
# or
my $thr = threads->create(sub { ... }, ...);
# or
my $thr = threads->create(\&func, ...);