Gossamer Forum
Home : Products : DBMan : Customization :

Modifying the value of a specific field

Quote Reply
Modifying the value of a specific field
Hi there

Smile I'm using the auto_delete mod. I wanna change the value of a specific field instead of deleting the current record (even it's not really make sense though Wink). Plus I wanna save the modified record to the db file as well. Could you guys please gimme some ideas how to make use of the following code? Thank you so much!! Crazy

Aladdin


sub auto_delete {
# ------------------------------------------
# Automatically removes entries older then $remove # days old.
#
my $remove = 14; # Number of days old.
my $date_field = 2; # Field Position of date field.


my $today = &date_to_unix(&get_date);
my $removeby = $today - ($remove * 86400);
my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
if ($removeby > &date_to_unix($values[$date_field])) {
# next;
}
print DB $_, "\n";
}
close DB;
}


Quote Reply
Re: Modifying the value of a specific field In reply to
You would need to change

Code:

if ($removeby > &date_to_unix($values[$date_field])) {
# next;
}
print DB $_, "\n";
to

Code:

%rec = &array_to_hash(0,@values);
$rec{'FieldName'} = 'new value';
print DB &join_encode(%rec);
I think that would do it. But be sure to backup your data before you try it.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
just wanna say thanks to JPD :-) In reply to
Hi JPD, Smile

In Reply To:
%rec = &array_to_hash(0,@values);
$rec{'FieldName'} = 'new value';
print DB &join_encode(%rec);

I think that would do it. But be sure to backup your data before you try it.
Wow.. thanks a lot!! but i eventually figure out some codes which most likely to yours. hehe.. actually i did pretty much the same as what you do. hopefully there wouldn't be any problems occured. plz.. Frown plz kindly let me know if i did it wrong. thxs!!!


my ($output);
%rec = &array_to_hash(0,@values);
$rec{'Reminder'} = "";
$output .= &join_encode(%rec);
print DB $output;


anyway, thank you so much!! Crazy

Aladdin

Quote Reply
Re: just wanna say thanks to JPD :-) In reply to
You don't need the line

my ($output);

In fact, that might cause you some problems. The rest of it looks fine.

JPD
http://www.jpdeni.com/dbman/