in reply to Jabber MUC bot channel list problem.

I would store users as a hash, rather than an array, making it much faster to determine whether the person is already in the list, or not, and also making deletions simpler.

my %roster; # to test for person being present, using a hash: if ( $roster{$jid} ) { .... } # to delete people when they leave: delete $roster{$jid};

I would re-initialize the list from the channel, say every half hour, to avoid going out of sync with reality. You might have some bug which loses people, or there might be a network problem which results in people joining or leaving without you being properly notified.

As for your code not working as you want it to, are you testing individual routines one by one, using Test::More or other testing frameworks? Can you run the program under the debugger, and determine data, inputs and outputs just before and just after an arrival ... use a private channel, where you can control arrivals. How about outputting a flood of data to a log file, and manually determining whether it's Doing The Right Thing?

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: Jabber MUC bot channel list problem.
by Jarek (Novice) on May 25, 2011 at 09:17 UTC

    Hi,

    Thank you for your reply. The one thing I cannot imagine a bit is how do I use this hash to store users. How do I add user to that hash ? If $jid is a key, then each key ($jid) must have a value. What is that value ? Anything ? Also I created some test script which checks your way of thinking.

    Please take a look:

    #!/usr/bin/perl use Data::Dumper; my %roster; @jid= qw |test1 test2 test3 test4|; foreach $jid (@jid) { $roster{$jid} = "0"; } foreach $jid (@jid) { print Dumper ($roster{$jid}); } @keys = keys %roster; print "Keys: @keys\n"; $jid = "test1"; if ($roster{$jid}) { print "something"; }
    Why the last if doesn't print "something" if the key exists ?

    Thank you for your help

    Regards.

      Any true value is fine for your hash, but unfortunately you've chosen 0 which isn't true. Use 1 instead, and the last test will then work as you want it to.
        Hi,

        This is working perfect. Thank you very much for your help. I can continue my work now:).

        Once again, thank you.

        Regards.