in reply to Script replaces instead of add

As roboticus pointed out, this:
$delaylist{ $_ } = $msg;
essentially says one message per nick. You could replace it with something like
$delaylist{ $_ } .= $msg;
which adds to the (still one) message (perhaps should add a linefeed or some such), or
push @{$delaylist{ $_ }}, $msg;
which says multiple messages per nick - housekeeping left as an exercise for the reader ;-)

In the latter case, you might want to change the semantics of delay-remove to remove

to that nick.

(TL;DR essentially the same as this)

Replies are listed 'Best First'.
Re^2: Script replaces instead of add
by geekism (Initiate) on Jul 24, 2015 at 03:06 UTC
    Using the above suggestions, appends to the prior nick: message, which i was already able to do. i need it to create a NEW message..
    For example (current code) nick message /delay add nick message nick message message. Expected results /delay list nick message /delay add nick message /delay list nick message nick message
      If I understand you correctly, the problem is now in your delaycmd and listdelay subs. instead of
      $server->command("query $nick $delaylist{$nick}");
      which sends the whole kaboodle as one message, make it
      $server->command("query $nick $_") for @{$delaylist{$nick}};
      (in case you changed your delaylist from hash of strings to HoA).

      Similiar for listdelays. Something like
      foreach (@nicks) { print "--> \cB$_\cB:\n"; print scalar @{ $delaylist{ $_ }} . " message(s)\n"; print "$_\n" for @{ $delaylist{ $_ }}; }

      BTW to me, it looks like the part with my %hash = ... and @isect was superfluous from the beginning. you should remove it, because otherwise it will distract you when you have the next change :-)

        This happens to give me the end result i wanted. Thank you. i dont understand what you're speaking about when you mentioned %hash.
      Alternative to my previous reply, if you don't want to "dive into" Perl Data Structures:

      The problem statement turns into: "how to represent multiple messages?"

      The most flexible is: as an array of individual messages. However, if you are certain there won't be, e.g., newlines in your messages, you can use that as a delimiter. That would make: In adddelays:
      $delaylist{ $_ } .= $msg . "\n";
      In listdelays:
      foreach (@nicks) { print "--> \cB$_\cB:\n"; print "$_\n" for split /\n/, $delaylist{ $_ }; }
      and finally, in delayer:
      print ("query $nick $_") for split /\n/, $delaylist{$nick};
      Luckily, split omits trailing empty fields, otherwise the code in adddelays would have to be more complicated. Thanks perl for autovivification and DWIM :-)