Laocoon_ has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a small Chatbot to say hello to people that enter my room.
Its supposed to only say Hi to people that enter the first time. Its all
working with the first guy but then it stops working.I thought it might be that
$1 is not being changed each iteration but i think it should..
Here's a code snippet :
for(;;){ sleep(1); $SendMessage->Call($readchat,0x00B1,0,$u); #select all chat $clipb->Empty(); #empty clipboard $SendMessage->Call($readchat,0x0301,0,0); #copy chat to clipboard $thechat = $clipb->Get(); #obtain chat from blipboard + next if $thechat !~ /\(\w{5}\)>\s(\w+)/; #Match stuff of format # "(Enter)> Some_Name" and #stores Some_Name in $1. next if $people{$1}; #next unless he is *new* $msg = "Hi $1 and welcome to my Room!"; #compose a hello message $people{$1} = 1; #Note he has entered } # --- Message is sent here --- }
Btw i know that thats a rather complicated approach to getting the Chat (copy to clipboard etc)
but its a RichEdit 2 Control and it doesn't respond to other stuff i tried. Any Ideas or suggestions?

Replies are listed 'Best First'.
Re: Chatbot - Pattern Matching in Loop
by dragonchild (Archbishop) on Sep 07, 2001 at 00:33 UTC
    Have you tried printing $1 out and seeing what it looks like?

    Also, I find it a little sketchy that you're copying the entire content's of the chatroom, but not iterating to find the new people. You need to iterate over the chat's contents and check every name.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Thank you :) i fixed it :)