Gossamer Forum
Home : Products : DBMan : Customization :

\n as delimeter

Quote Reply
\n as delimeter
Hi!

I want each field of each record to be saved as a new line on the data file; so that the result data file can be used with some other script I have.

It looks like changing
$db_delim = '|';
to
$db_delim = "\n";
works when adding a new record. Resulting data file is as what I want it to be. However, modifying, or deleting data doesn't work.

Is there anyway to work this?
Thanks!

I need help, please!

Quote Reply
Re: \n as delimeter In reply to
Unfortunately, you have chosen characters, which serve a special function in Perl...\n = line breaks.

If your goal is to use a pipe delimited database format, then you should use:

Code:

$db_delim = "\t";


as discussed in the following Thread:

http://www.gossamer-threads.com/...=25&Old=allposts

Regards,

Eliot Lee
Quote Reply
Re: \n as delimeter In reply to
Well, a line break is what I want!!! :)

So, if fields are name, phone, email; I want the records saved as:

jane
2324534233
jane@dfsdf.com
peter
7456563432
peter@kjf.com

That's why I'm asking for \n :)

Quote Reply
Re: \n as delimeter In reply to
I'm desperately looking for a solution still, if you have any, please!!! :))

Quote Reply
Re: \n as delimeter In reply to
You have chosen the one delimiter that is not allowed in DBMan. The script uses the newline character to tell one record from another. This is one of the few things I've come across that cannot be done.

If you'd be willing to go into more detail of what you want to do and why, I might be able to help you with a workaround.


JPD
Quote Reply
Re: \n as delimeter In reply to
The script is setup to read and write to a db where each record is on it's own line. I don't belive it would function by reading a database stored on many lines without being heavily modified.

What program are you trying to use in conjunction with DBMan. Perhaps modifying the other program may work.

Quote Reply
Re: \n as delimeter In reply to
I have a ticker java applet, which reads data from text file, with 3 variables, defined one on each line...

I thought it would be much more easier to modify the cgi than java.

If it is really very difficult to modify DBman, can you advice me anyother database script which I can do this with? I need add, delete, modify, list all functions and of course, each field recorded on a new line as I mentioned.

Thank you in advance

Quote Reply
Re: \n as delimeter In reply to
DBMan is the only database script I'm familiar with. Sorry.

You could possibly write a "mirror" db file with all of the fields on separate lines. But it would be a real bear to modify or delete records.


JPD
Quote Reply
Re: \n as delimeter In reply to
What about this:

Is it possible to add a sub, which will work after each add, modify or delete, and will open the .db, replace all pipes with \n and save it as a different file - which will be used by my java?

I think this will help me, right? The problem: I dont know how to add such a sub! :))

Quote Reply
Re: \n as delimeter In reply to
Yes, you could do that. It will slow things down quite a bit, but you could do it.

Add the following to db.cgi

Code:

sub create_mirror_file {
$output = '';
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
foreach $line (@lines) {
$line = s/\|/\n/g;
$output .= "$line\n";
}
open (MIRROR, ">$db_mirror_name") or &cgierr("unable to open $db_mirror_name. Reason: $!");
if ($db_use_flock) {
flock(MIRROR, 2) or &cgierr("unable to get exclusive lock on $db_mirror_name.\nReason: $!");
}
print MIRROR $output;
close MIRROR;
}
You'll also need to add a line to your .cfg file like


$db_mirror_name = $db_script_path . "/mirror.db";


Create an empty file -- mirror.db -- and set the permissions to 666.

In each of the subroutines that change the .db file -- sub add_record, sub modify_record and sub delete_records -- just before the line that sends the script to the "success" page, add the following:

&create_mirror_file;

Then use the mirror.db file for your java thing.



JPD
Quote Reply
Re: \n as delimeter In reply to
It doesn't work :(

Only an empty line is added to the mirror.db when I add a record.

By the way, you must be some kind of angle, trying to help so many people here :) Thanks!

Quote Reply
Re: \n as delimeter In reply to
In JP's code
replace $line = s/\|/\n/g;

with $line =~ s/\|/\n/g;

That should do it.

rog

Quote Reply
Re: \n as delimeter In reply to
Thanks!!! :-)

I luv you all! ;-)


Quote Reply
Re: \n as delimeter In reply to
Thanks rog!



JPD