Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I like the way you get the chatterbox, by breaking into the nodelet units. I may do that instead of the match on the whole page I do right now.

I think the problem with your cache is that you are resetting old messages every time. Here's what happens. Assume the first time through the chatbox has the following lines:

user1: blah user2: bleh user3: blih
So you add those to $newmessage, which then becomes $oldmessages. The next time, the box contains:
user1: blah user2: bleh user3: blih user1: howdy
As you go through the lines, the only one that gets added to $newmessages is the last one, because the others are already in $oldmessages.

Then, and here is the problem, you remove $oldmessages! So the only message you have a record of is the last one. So the next time through, the first three messages are printed again, because they are no longer in the cache.

I don't think you need the juggling of $old and $newmessages. You can just keep one hash where you cache all the messages. The problem with this (and the reason why I didn't do it that way in my code) is that you have no way of knowing which messages are older or newer, so unless you attach a timestamp to each entry, your cache will grow indefinitely. Furthermore, if the same user says the same thing in two different occasions, the second time through it will not be printed because your program will think it's a repeated message.

Hope this helps,

--ZZamboni


In reply to RE: RE: Get chatbox lines by ZZamboni
in thread Get chatbox lines by ZZamboni

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (6)
    As of 2014-08-31 00:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (294 votes), past polls