in reply to Re: Script replaces instead of add
in thread Script replaces instead of add

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

Replies are listed 'Best First'.
Re^3: Script replaces instead of add
by soonix (Chancellor) on Jul 24, 2015 at 08:22 UTC
    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.
        This block in adddelays is superfluous:
        my %hash = map { $_, 1 } @nicks; @nicks = keys %hash; if (keys %delaylist) { my @isect = (); map { $hash{$_} = 1 } keys %delaylist; @isect = grep { $hash{$_} } @nicks; if (@isect) { # removedelays(@isect); } }
        It probably was supposed to remove those messages, which later would be overwritten anyway, so it was superfluous from the very beginning...
Re^3: Script replaces instead of add
by soonix (Chancellor) on Jul 24, 2015 at 09:26 UTC
    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 :-)