Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I must be able to tie %chat to both objects otherwise it's useless

Pretty strong words, partner ;-) I think what you mean is that to pull this off you must be able to represent the data in a sorted manner.

First off, sauoq was right on about IxHash.

Second, diotalevi says to use $DB_BTREE. An excellent suggestion, as long as you use a sensible key - maybe date/time stamp - and be aware of the possibility of duplicates. It will always be sorted - it's stored in a balanced tree. The key your script uses is $cnt, but I don't see it being initialized anywhere (probably not a sensible key ;). Every message is stuffed into the same slot, overwriting the previous message.

The most straightforward short-term solution for you IMO would be to use $DB_RECNO like so:

# tie your array to the file tie @chat, 'DB_File', 'chat', O_CREAT | O_RDWR, 0644, $DB_RECNO; # push the message info onto the array push @chat, "Message number $_" for (1 ..20); # print the last five messages print join "\n", @chat[-5 .. -1]; __END__ output: Message number 16 Message number 17 Message number 18 Message number 19 Message number 20

You'll be able to treat @chat like an ordinary array. As a bonus, you'll be able to view or modify the chat db file with any text editor.


In reply to Re: Re: Re: Re: Re: Re: DB_File, not saving by jsprat
in thread DB_File, not saving by sulfericacid

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 surveying the Monastery: (8)
    As of 2014-07-31 21:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (253 votes), past polls