Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Storing karma

by Anonymous Monk
on Jun 28, 2001 at 12:40 UTC ( [id://92212]=note: print w/replies, xml ) Need Help??


in reply to Storing karma

How about (untested)
open X,'karma.txt';undef$/; my %x=split/\s+/,<X>; $x{$user}++; close X;open X,'>karma.txt'; print X "$_ $x{$_}\n" for keys %x; close X;

Replies are listed 'Best First'.
Re: Re: Storing karma
by Anonymous Monk on Jun 28, 2001 at 17:36 UTC
    Anonymous Monk seems to have the right idea: Just load the whole database into a hash, increment the user element (it will be created if non-existant), and save the whole thing overwriting the file.

    If the user database gets too large to be handy, an upgrade would be to tie the hash to a database of some kind. There is one that seems universal to perl installations. ( NDBM? )

    use NDBM_File; tie(%x, 'NDBM_File', 'karma.db', 1, 0); $x{$user}++; untie(%x);
    Here the hash keys and values are maintained in the database and some subset is also maintained in the hash itself, but elements are transferred implicitly from the database to the hash (and vice-versa) as needed. The 'untie' line puts all new and changed elements out to the database.

    That last paragraph is clear as mud, hmm.. This page may be of use (or not).

    Amused

    Edit by tye

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found