Click to See Complete Forum and Search --> : CGI Help. Change output from pipe to tab


Aronya1
12-12-2005, 11:47 PM
CGI ignoramous here, so please be kind. Here's what I'm trying to accomplish:

I have a CGI script that will read a .txt file and input the contents to a .shtml file. The contents of the text file are currently pipe ( | ) delimited. I need to be able to change to tab delimited.

Here is the code that I think is in question (no doubt, I'm wrong):

From the .cgi file that creates the .txt file:
print FILE "$in{'id'}|$in{price}|$in{ft2}|$in{beds}|$in{baths}|$in{city}|$description|$in{'picture'}\n";

From the .cgi file that outputs to .shtml:
PrintTag
foreach $i (@indata)
{
chomp($i);
($id,$mls,$price,$ft2,$beds,$baths,$city,$description,$picture) = split (/\|/,$i);

My best guess is that in the first instance I need to replace the pipe characters with whatever symbol will represent a tab, and in the 2nd instance, I need to edit the last little bit: split (/\|/,$i);

Any help would be appreciated. I can post more of the code if needed. Just trying to be conservative.

Many thanks.
Tim

NogDog
12-12-2005, 11:56 PM
I believe you want to replace the "|" with "\t" for the tab.

Aronya1
12-13-2005, 12:12 AM
Thanks for the quick reply, but exactly where am I putting this? I tried replacing the "|"s in this line:
print FILE "$in{'id'}|$in{price}|$in{ft2}|$in{beds}|$in{baths}|$in{city}|$description|$in{'picture'}\n";

and here:
split (/\|/,$i); *now looks like this: (/\t/,$i);

The result is that the .txt file is still created with "|" delimiters (and now is not being written to the output file). Where am I going wrong?

edit**************
Nevermind. I got it. Was on the right track. Just didn't find all the instances of the "|" character. Thanks again for your help, Nogdog.