Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: DB_File, not saving

by sauoq (Abbot)
on Jul 17, 2003 at 19:08 UTC ( [id://275339]=note: print w/replies, xml ) Need Help??


in reply to DB_File, not saving

After you tie %chat to DB_File you re-tie it to Tie::IxHash. (So, you never really use DB_File at all.)

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: DB_File, not saving
by jsprat (Curate) on Jul 17, 2003 at 19:20 UTC
    Commenting out unlink "chat"; would probably help too...

    Update: I meant in addition to sauoq's comment, not instead of.

      He's just doing that once at the beginning of the script to remove his old file before writing a new one. That shouldn't matter (as long as he wants to start fresh each time the script runs.)

      Update: jsprat is correct. The file should not be unlinked. (It is obvious, on closer inspection, that the script is useless without it.)

      -sauoq
      "My two cents aren't worth a dime.";
      
        I don't think he wants to start fresh each time. He wants to save the data so he can display more than one line.

        It looks like a CGI script that wants to accept a line of chat, then display the previous 10 lines. What it actually does is this:

        1. deletes all previous messages
        2. creates the db file, ties %chat
        3. unties %chat, thereby not storing any messages
        4. accepts a new message
        5. displays the last 10 messages (which were just deleted!)

        Not only is the %chat untied from the the DB_File when it's tied to TIE::IxHash (as you pointed out), the script is deleting the DB_File every time it is hit.

Re: Re: DB_File, not saving
by sulfericacid (Deacon) on Jul 17, 2003 at 19:20 UTC
    Then what do you suggest? I need to tie %chat to Tie::IxHash to retain insertion order and I need tie it to the DB_File or it's useless.

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
      Then what do you suggest?

      I suggest you use an array instead of a hash and tie to DB_file using the DB_RECNO file type.

      -sauoq
      "My two cents aren't worth a dime.";
      

        Also good, DB_BTREE. The keys are always in sorted order.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://275339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-18 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found