Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flat text database viewed in html 1

Status
Not open for further replies.

renerene

Technical User
Sep 27, 2001
2
AU
Hi,
I run a flat text database and want to view it in html format on the web.
These are the entries:
e-mail|title|url|description|category|spare|time|date
e-mail|title|url|description|category|spare|time|date
etc...

I need 1 long list in html like this:
title description url e-mail time date
title description url e-mail time date
etc...

No editing of the database is needed. No templates, just a list with clickable e-mails and urls.

Where do I start?
 
Maybe something along the lines of:
Code:
open (INF, $filename) or $error=1; #or a die etc...
while(<INF>)
{
    #read the line, split it and display the html
    ($email,$title,$url,$desc,$cat,$spare,$time,$date) = split /|/, $_;
    # if you want to format, say in a table then..
    print &quot;<tr><td><a href=&quot;$url&quot;>$title</a></td>&quot;;
    print &quot;<td>$description</td>&quot;;
    print &quot;<td><a href=&quot;mailto:$email&quot;>$email</a></td>&quot;;
    print &quot;<td>$time</td><td>$date</td></tr>\n&quot;;
}


Cheers
Loon
 
Hi,

Thanks for that.
I have mixed and matched a bit and came up with this:
#!/usr/bin/perl

$data_file=&quot;links.txt&quot;;

open(DAT, $data_file) || die(&quot;Could not open file!&quot;);
@raw_data=<DAT>;
close(DAT);

print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML><BODY>&quot;;

foreach $biglist (@raw_data)
{
chop($biglist);
($email,$title,$url,$desc,$cat,$spare,$time,$date)=split(/\|/,$biglist);
print &quot;$title $url $desc $email $time $date&quot;;
print &quot;<BR>\n&quot;;
}

print &quot;</BODY></HTML>&quot;;

This works OK but as soon as I try to put a clickable link in like so:

print &quot;$title <a href=&quot;$url&quot;>$url</a> $desc $email $time $date&quot;;

I get a server error.
Can you see what is happening here.

 
To add the link correctly, you need to put the escape backslash:

print &quot;$title <a href=\&quot;$url\&quot;>$url</a> $desc $email $time $date&quot;;

Also, a little suggestion: If you're using perl version 5, use the chomp function instead of chop. Here's an example:

foreach $biglist (@raw_data)
{
chomp($biglist);
($email,$title,$url,$desc,$cat,$spare,$time,$date)=split(/\|/,$biglist);
print &quot;$title $url $desc $email $time $date&quot;;
print &quot;<BR>\n&quot;;
}

What's the difference? Well, if you are running perl version 5, then chomp only cut out the newlines. But chop function will cut out one line from the file. Just to be in safe, using chomp is a very good idea.
There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top