Thread Sockets / Hash - Switch Statement (4 answers)
Opened by Gast at 2005-01-10 00:45

Gast Gast
 2005-01-10 00:45
#50656 #50656
Hallo.

Wieso wird bei folgendem Code nie die if-Bedingung erfüllt? Im Client wird z.B. quit eingegeben, aber $exit = 1; last; wird nie ausgeführt :-/

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
print $client "Command? ";

while ( <$client> ) {
next unless /\S/; # blank line

my %commands = (
'quit' => sub { $exit = 1; last; },
'title' => \&title,
'next' => \&next_title,
'prev' => \&prev_title,
);

if ( defined( $commands{$_} ) ) {
$commands{$_}->();
} else {
print $client "Commands: quit title prev next", $CRLF;
}

View full thread Sockets / Hash - Switch Statement