And here's a from the docs (perldoc db_file) hack to
read-in your text and create a dbm:
use strict ;
use DB_File ;
use vars qw( %h $k $v ) ; # hash, key value
tie %h, "DB_File", "memberpoints", O_RDWR|O_CREAT, 0640, $DB_HASH
or die "Cannot open file 'memberpoints': $!\n";
# Load in the whole file data file into the hash/dbm
open (FILE, "memberpoints.txt") or die "Can't read: $!";
while (<FILE>) {
next unless /-/;
chomp;
my ($name, $number) = split "-";
$h {$name} = $number;
}
# print the contents of the hash/dbm
while (($k, $v) = each %h) {
print "$k -> $v\n"
}
untie %h ;
Note: you'll do this once, then you need to write your update code
along the lines of:use strict ;
use DB_File ;
use vars qw( %h $k $v ) ; # hash, key value
tie %h, "DB_File", "memberpoints", O_RDWR|O_CREAT, 0640, $DB_HASH
or die "Cannot open file 'memberpoints': $!\n";
# update
$h{vegeta} += 6;
# print the contents of the db (debuggin)
while (($k, $v) = each %h) {
print "$k -> $v\n"
}
untie %h ;
Very rough but its cold here and my fingers are getting
too stiff to type.
Update: Fruit? it really was cutnpaste ...
a |