Deliminated Flat File => Displayed In HTML ?
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
...post some sample lines from the flatfile...and explain how you wish to display the the data in the page...
Flat File Example
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.
Attached Files
...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.
Attached Files
CyCo
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
HTML Template: See Attached
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
Attached Files
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.
Last edited by CyCo; 05-20-2004 at 10:53 AM .
Here's a fairly easy way to do it:
1. Create a file called template.html and put this in it:
Code:
<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:
Code:
#!/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> </td>
<td align="center">Date</td>
<td align="center">Country</td>
<td> </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"> </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
Hi this213,
...it appears that you are missing a string terminator in your code...
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...
}
oh well, proves I'm human too.
great reply...
Cheers!
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...
Computer Zen:
Program aborting
Close all that you have worked on
You ask far too much
Or perhaps you only just want us to think you're human!
hmmm... think I've heard that before.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks