Hi,
I've removed the if statement that checks the hash so now the code looks
like this:
while (my ($client, $client_address) = $server->accept()) {
$client->autoflush(1);
my ($port, $packed_ip) = sockaddr_in($client_address);
my $client_ip = inet_ntoa($packed_ip);
my $stamp = ×tamp;
print LOGFILE "$stamp - Client ($client_ip) connected.\n" if $DEBUG ==
1;
$client->recv($recv, 128);
#if (exists($commands{$recv})) {
# $client->send("Works!");
# } else {
chomp($recv);
$client->send("Doesn't work! - $recv - The command should appear
before this.");
# }
}
and I get the following output:
[EMAIL PROTECTED]:~$ telnet localhost 6666
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello <-- i type this in.
- The command should appear before this.Connection closed by foreign host.
And below is the output when I don't do a chomp();
[EMAIL PROTECTED]:~$ telnet localhost 6666
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
Doesn't work! - hello
- The command should appear before this.Connection closed by foreign host.
I hope this clears up what is happening.
Thanks,
Shane
On 12/10/2007, Scott Ragen <[EMAIL PROTECTED]> wrote:
>
> > $client->recv($recv, 128);
> > chomp($recv);
> >
> > if (exists($commands{$recv})) {
> > $client->send("Works! Received: $recv");
> > } else {
> > $client->send("Doesn't work! We received this: $recv");
> > }
> > }
> >
> > The code above doesn't print out anything for $recv, however if I remove
> the
> > chomp($recv) it works fine. Anyone got any idea's why running a chomp on
> > this variable causes it to not be displayed at all? The variable does
> > contain a newline so I do need to have it removed.
> >
> Hi Shane,
> Can you be a little more specific?
> When you chomp, do you get the "Doesn't work" return with nothing from
> $recv variable?
> When you don't chomp, do you also get "Doesn't work" returning the string
> from $recv variable?
>
> What I'm asking, is does the hash list also contain a new line, so when
> you chomp, it no longer matches?
>
> Regards,
>
> Scott
>
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html