Click to See Complete Forum and Search --> : Deliminated Flat File => Displayed In HTML ?


surge42
05-13-2004, 06:15 PM
I have a pipe delimited flat file that I wish to display in a HTML document.

I'm new to Perl and I was wondering if anyone knew of a script that could do such a thing for me.

Ultimatley I'd like to have some control over how the data is displayed in the document. For instance I'd like each line of data to get its own page.

Where could I go to find such a script?

Is there a better way of describing what I want? I've been doing a few Googles on this but I'm afraid I'm not using the right words.

Thanks for you help

Scott
West Chester PA

CyCo
05-15-2004, 12:10 PM
...post some sample lines from the flatfile...and explain how you wish to display the the data in the page...

surge42
05-18-2004, 05:18 PM
CyCo,
Lets say the attached flat file is appended every time a person fills out my form.

What I'd like to do is have a script that can pars that data and out put it to a html page. Each line in the flat file would get its own page.

I don't really care about the following.

HTML naming
HTML look and feel.

I can modify that stuff later.

CyCo
05-19-2004, 01:45 PM
...well, if you aren't interested in any major HTML formatting, then the little script attached (I had to attach it, the forum was messing up the code) will do...

of course, if you would be a little less "vague", I'm sure there is a much easier way to accomplish this whole "form to flatfile" scenario from the outset.

CyCo
05-19-2004, 01:49 PM
oops...

surge42
05-19-2004, 09:29 PM
Thanks Cyco,

Yep, I was intentionally being vague in hopes of allowing an easy response from you.

Now that I think about it, being vague is probably more of a hindrance than a blessing.

I'll apply the script and find out what it prints.

You know what I'll do... I'll build a html page to show you what kind of formatting I'm looking for. My next message will have the file.

Surge42

surge42
05-19-2004, 10:16 PM
Cyco,

Ok, The attached file is an example of what I'm looking for as far as printed html formatting.

I can't wait to see how......

the perl knows what part of the delaminated fields get printed in what table cell. The reason being is that there is no ID defining each field. Would you assign id's to each line of data?

It looks like start_html removes the need to use tags what so ever.
How the heck would one code tables and fonts with this method.

You can bet I'll apply what you show me on this script to the other one you sent me. You know the field name script.

Surge

CyCo
05-20-2004, 10:44 AM
This issue is a very easy one to remedy, but it seems there are too many inconsistencies in your explanation of the situation to me. First of all, the sample flatfile you provided suggests 10 different fields. Your sample HTML page suggests 8 fields. Plus, each newline in the form_data.txt file starts with a delimiter...which is un-necessary. So, why don't we just take a look at the script that is writing the data to the flatfile and fix that up first, and then everything will be good to go.

this213
05-21-2004, 03:11 PM
Here's a fairly easy way to do it:

1. Create a file called template.html and put this in it:

<html>
<head><title><mysite title></title>
</head>
<body>
<mysite main>
</body>
</html>

You can change this template however you want to, the <mysite ~~> tags are what's important here.

2. Create this script:

#!/usr/bin/perl
open(FILE,"filename.txt");
@stuff = <FILE>;
close FILE;
chomp @stuff;
$aatitle = "My Site Title";
$aamain = qq~
<table align="center" width="90%" border="0">
<tr>
<td>&nbsp;</td>
<td align="center">Date</td>
<td align="center">Country</td>
<td>&nbsp;</td>
<td align="center">Name</td>
<td align="center">Street Address</td>
<td align="center">City</td>
<td align="center">State</td>
<td align="center">Zip Code</td>
<td align="center">Phone</td>
<td align="center">Message</td>
<td align="center">&nbsp;</td>
</tr>
~;

foreach $el (@stuff) {
my($something,$date,$country,$something1,
$name,$address1,$city,$state,$zipcode,$phone,
$message,$something2) = split(/\|/,$el);
$aamain .= qq~
<tr>
<td>$something</td>
<td align="center">$date</td>
<td>$country</td>
<td>$something1</td>
<td>$name</td>
<td>$address1</td>
<td>$city</td>
<td>$state</td>
<td>$zipcode</td>
<td>$phone</td>
<td>$message</td>
<td>$something2</td>
</tr>
}

$aamain .= qq~</table>~;
&template;

sub template {
print "Content-type: text/html\n\n";
@iztmpl=();
open(TMPL,"template.html") || die "Cannot Open template.html: $!";
@tmpl= <TMPL>;
close(TMPL);
for(my $i = 0; $i < @tmpl; $i++) {
$curline = $tmpl[$i];
$curline =~ s~<mysite\s+(\w+)>~${"aa$1"}~g;
print $curline;
}
}

Where filename.txt is the location of your form data text file, that should output what you want.

I was bored - waiting to get off work.

hth
This

CyCo
05-24-2004, 12:06 PM
Hi this213,
...it appears that you are missing a string terminator in your code...


foreach $el (@stuff) {
my($something,$date,$country,$something1,
$name,$address1,$city,$state,$zipcode,$phone,
$message,$something2) = split(/\|/,$el);
$aamain .= qq~
<tr>
<td>$something</td>
<td align="center">$date</td>
<td>$country</td>
<td>$something1</td>
<td>$name</td>
<td>$address1</td>
<td>$city</td>
<td>$state</td>
<td>$zipcode</td>
<td>$phone</td>
<td>$message</td>
<td>$something2</td>
</tr>~; # <-- HERE...
}

this213
05-24-2004, 12:12 PM
oh well, proves I'm human too. :)

CyCo
05-24-2004, 12:28 PM
great reply...
Cheers! ;)

Aronya1
05-25-2004, 02:18 PM
Originally posted by this213
oh well, proves I'm human too. :) Or perhaps you only just want us to think you're human! Very clever...

this213
05-25-2004, 03:00 PM
Or perhaps you only just want us to think you're human!

hmmm... think I've heard that before.