Protruth
Protruth

Reputation: 11

How do I add this value to an Array and it stays in the script

I want to add a command that adds numbers to the array.

This is what i have exactly:

my $ownerids = ('374867065');

Then later in the script i have this:

if($ownerids == $spl2[0]){
    if (index($message, "!adduser") != -1) {
        $msg = $spl[1];
        $send = "<m t=\"User Added $msg\" u=\"$botid\"  />\0";
        $socket->send($send);
        push (my $ownerids, "$msg");
    }
}

I am on a chatbox and this is a chatbot, i want to make it when i say !adduser (thereid) it adds them to a list and they can use the bot commands, and also i want a Delete User, If you can help this will be MUCH appretiated.

Upvotes: 0

Views: 41

Answers (1)

Miller
Miller

Reputation: 35208

If you want ownerids to be an array, then you must prefix it with a @

my @ownerids = ('374867065');

Then to add an element, you can push

push @ownerids, "$msg";

However, you're going to need to fix your other references to @ownerids so it's treated like an array. For example, your first if looks like it's intending to see if $spl2[0] is an owner. If that's the case, then you'll need to grep the array:

if(grep {$_ == $spl2[0]} @ownerids) {

Upvotes: 2

Related Questions