For anyone who's interested, here's the Jaad/davido pool-solution in Perl:

package Chat::Pool; # 16 should suffice. use constant POOL_SIZE => 16; sub new { bless [ # $self->pool: Arrayref of ["#fg","#bg"]-pairs. # Fixed size. [ $_[0]->precalc_colors(POOL_SIZE) ], # $self->col->[$id] contains the ["#fg","#bg"]-pair of a user. [], ] => shift } sub tick { my ($self, $id, $time) = @_; # If we haven't allocated a color for $id... unless(defined $self->col->[$id]) { # Take one from the pool (pop), assign in to $id, and unshift it. # All in one line :) unshift @{ $self->pool }, $self->col->[$id] = pop @{ $self->pool } +; } } # Return the allocated color for $_[1]. sub color {@{ $_[0]->col->[$_[1]] }} # Precalculate the pool. sub precalc_colors { my ($self, $num) = @_; local $_; return map {[ $self->calc_color($_, $num) ]} 0..$num-1; } # calc_color as in OP sub pool : lvalue { $_[0]->[0] } sub col : lvalue { $_[0]->[1] }

This solution is really easy :)

Update: If you don't want HTML-colors, but ANSI (e.g. for STDOUT), you can use:

package Chat::Pool::ANSI; use base "Chat::Pool"; sub precalc_colors {( ["\033[31;1m"], ["\033[32;1m"], ["\033[33;1m"], ["\033[34;1m"], ["\033[35;1m"], ["\033[36;1m"], ["\033[37;1m"], ["\033[31m"], ["\033[32m"], ["\033[33m"], ["\033[34m"], ["\033[35m"], ["\033[36m"], )} # later... printf "%s%s%s\n", ($chat->color($id))[0], $text, "\033[0m";

In reply to Re: Coloring IRC logs nicely by iblech
in thread Coloring IRC logs nicely by iblech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.