Gossamer Forum
Home : Products : DBMan : Customization :

Help with reading a file correctly

Quote Reply
Help with reading a file correctly
Please help solve this problem. For DBMan the following subs are used to have people save their favorites records into a separate database. Saving to the database works fine.

The problem is then in reading the file (sub view_favorites) and only returning the exact record IDs saved for each user.

A sample of the favorite.db looks like:

534-jackstraw|28-Mar-2002
494-jackstraw|28-Mar-2002
269-jackstraw|28-Mar-2002
614-lchiang|28-Mar-2002
1062-oldmoney|25-Apr-2002
649-kjellkk|07-May-2002
114-omegadm|15-May-2002
6-oldmoney|15-May-2002

What is happening is on the single digit record IDs such as # 6. It will then display all records containing the number 6.

Any help on getting sub view_favorites to display the exact record IDs would be appreciated.


sub add_to_favorites {
#---------------------------------------
open (FAVE, "<$db_favorites") or &cgierr("error in add_to_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
LINE: while (<FAVE> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[0] eq "$in{$db_key}-$db_userid") {
$message = "That listing is already in your favorites list";
}
}
close FAVE;
unless ($message) {
open (FAVE, ">>$db_favorites") or &cgierr("error in add_to_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) {
flock(FAVE, 2) or &cgierr("Unable to get exclusive lock on $db_favorites.\nReason: $!");
}
$date = &get_date();
print FAVE "$in{$db_key}-$db_userid|$date\n";
close FAVE; # automatically removes file lock
$message = "Listing added to favorites list";
}
&html_favorite_success($message);
}
sub view_favorites {
# --------------------------------------------------------
open (FAVE, "<$db_favorites") or &cgierr("error in view_favorites. Unable to open favorites file: $db_favorites.\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
@flines = <FAVE>;
close FAVE;
foreach $fline (@flines) {
@data = &split_decode($fline);
if ($data[0] =~ /(.+)-$db_userid/) {
$in{$db_key} .= "$1|";
}
}
chop $in{$db_key};
$in{'re'} = 1;
$in{'ww'} = 1;
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure("No favorites on file");
}
}

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Subject Author Views Date
Thread Help with reading a file correctly LoisC 8603 May 15, 2002, 8:32 PM
Post Re: [LoisC] Help with reading a file correctly
oldmoney 8463 May 15, 2002, 10:40 PM
Thread Re: [LoisC] Help with reading a file correctly
Paul 8414 May 16, 2002, 2:03 AM
Thread Re: [Paul] Help with reading a file correctly
LoisC 8422 May 16, 2002, 10:03 AM
Thread Re: [LoisC] Help with reading a file correctly
Paul 8451 May 16, 2002, 10:41 AM
Post Re: [Paul] Help with reading a file correctly
LoisC 8391 May 16, 2002, 10:52 AM
Thread Re: [Paul] Help with reading a file correctly
oldmoney 8394 May 16, 2002, 10:57 AM
Thread Add to Favorites
LoisC 8058 Mar 20, 2005, 9:36 AM
Thread Re: [LoisC] Add to Favorites
fuzzy logic 8018 Mar 21, 2005, 5:51 PM
Thread Re: [fuzzy logic] Add to Favorites
LoisC 8068 Mar 22, 2005, 7:34 AM
Thread Re: [LoisC] Add to Favorites
LoisC 8010 Mar 22, 2005, 9:57 AM
Post Re: [LoisC] Add to Favorites
fuzzy logic 8000 Mar 22, 2005, 8:48 PM