in reply to Re^3: How to store an array in the store of Bot::BasicBot::Pluggable::Module?
in thread How to store an array in the store of Bot::BasicBot::Pluggable::Module?

Boy, was I stupid... Thank you! It works now with the following snippet:

if ( $body =~ /^!setq\s*$/ ) { my @order = ("orange","peach","banana"); $self->set("fruit_order"=>\@order); my $o= $self->get("fruit_order"); my $ou= "order: ".join(", ",@$o); return $ou if (ref $o eq 'ARRAY'); return "no order :("; }

Why it didn't work before, you ask? Well, if you look closely you'll find that I tried to use return with an array. It will not dump the contents of the array into the channel though but expects a scalar (so it sent a 0 for an empty array and a 3 for the above example). I had to use string concatenation and a helper variable first to get return to paste the contents of the array.

Works now, thanks again!

  • Comment on Re^4: How to store an array in the store of Bot::BasicBot::Pluggable::Module?
  • Download Code

Replies are listed 'Best First'.
Re^5: How to store an array in the store of Bot::BasicBot::Pluggable::Module?
by jethro (Monsignor) on Jan 22, 2011 at 17:34 UTC

    Returning an array works too, you just have to provide list context on the calling side, i.e.

    sub x { ... return @f; } my @r= x(...);

    would work. You don't need the concatenation

      I can't provide list context on the calling side though because the "return" of the function is defined/used by the Bot::BasicBot::Pluggable::Module class (or one of it's ancestors) to directly speak to the irc channel. Everything that gets returned should be said in the channel by the bot. Apparently the programmers of that module didn't think of a possible list context case.

      So it was one of my mistakes to assume that array elements (of a returned array) would be printed out (=said in the channel) automatically...