Gossamer Forum
Home : Products : DBMan : Customization :

How Do I Do This? What Am I Missing?

Quote Reply
How Do I Do This? What Am I Missing?
Observe the following:

Code:
open (OPTIONS, ">/databases/$db_userid$in{'pw'}.txt");

if ($db_use_flock) {
flock(OPTIONS, 1);
}@lines = <OPTIONS>;close OPTIONS; LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/|/, $line); $Name = $data[3];
$Email = $data[4];
$Phone = $data[5];
last LINE;
}


Then in my form I can use something like:

Your name is: $Name

Your email address is: $Email

etc.

I cannot get it to work. Am I missing something?

Basically I want to open a text file that is in pipe delimited format similar to the default db, split the values and use them as I showed above. If it helps, each text file database only has one record in it on one line.

Thanks in advance for any help. Ask me questions if you need to!
Quote Reply
Re: [BrianYork] How Do I Do This? What Am I Missing? In reply to
Anyone?

Here is what I am trying to do again:

open (DB, ">/databases/test.txt");
if ($db_use_flock) { flock(DB, 1); }

@data=<DB>;
close(DB);

foreach $line(@data) {
@ThisLine = split(/\|/,$line);
$Name = $ThisLine[2];
}

Example database format:

01|5|Joe Cool

I then call it in my html using $Name.

Example: My name is $Name should print: My name is Joe Cool

However, I get nothing!

What am I doing wrong or what am I missing?
Quote Reply
Re: [BrianYork] How Do I Do This? What Am I Missing? In reply to
Anyone?

Anyone?

IM GOING NUTS TRYING TO FIGURE OUT WHY THIS IS NOT WORKING! Mad

Thanks!
Quote Reply
Re: [BrianYork] How Do I Do This? What Am I Missing? In reply to
Here is a snippet that I know works. This is used when you have another db file (flat file -ascii, pipe delimited) and you want to match a records ID with one in the other db. See if you can hack it to suit your needs.

Code:
$db_name_list = '../data/data.db'; #name of other db file
open (OTHER, "<$db_name_list") or &cgierr("error!"); #open file or return error if not able
if ($db_use_flock) { flock(OTHER, 1); } #temporarily lock other file
while (<OTHER>) { #begin looping thru other file line by line
next if /^$/; #skip blank lines
next if /^#/; #skip comment lines(?)
chomp; #remove line breaks
@data = &split_decode($_); #use sub to convert break commands and delimiters
if ($data[9] eq "$rec{'UserID'}") { #field position (starts with zero) to match
$UCompany = $data[1]; #field position of data from line w/matching
$UBranch= $data[2]; #field position of data from line w/matching
} #may possibly want to add 'close (OTHER)'
} #at end of this script - double check close syntax
Quote Reply
Re: [Watts] How Do I Do This? What Am I Missing? In reply to
Thanks, Watts!

Your code worked and so would have mine. I found out that I had my path wrong - I had / at the beginning of my open and needed to remove it - did not even notice it after looking for hours.

Anyway, here is working code:

Code:
$db_name_list = 'databases/test.txt'; #name of other db file
open (DB, "<$db_name_list"); #open file or return error if not able
if ($db_use_flock) { flock(DB, 1); } #temporarily lock other file
while (<DB>) { #begin looping thru other file line by line
next if /^$/; #skip blank lines
next if /^#/; #skip comment lines(?)
chomp; #remove line breaks
@data = &split_decode($_); #use sub to convert break commands and delimiters
#field position (starts with zero) to match
$Name = $data[0];
$Phone = $data[1];
close DB;

}


In my html, I call it as follows:

Name: $Name

Phone: $Phone

Thanks again for all of your help!