freelanceprogrammers.org Forum Index » Perl

Need help


View user's profile Post To page top
ckbk2002 Posted: Fri Jun 09, 2006 1:45 am


Joined: 09 Jun 2006

Posts: 2
Need help
Hello, I am attempting to build a page that uses a cgi script to
extract info from
a delimited text file database and then place it into an html file for
viewing (see files below.) The database will contain "tips for the
day" and is
arranged in four fields containing the month, day, year, and tip or
event
info (I have "dummy data" in it now.). The script gets the current
date and compares it to the date listed for the tip. If they match it
extracts that record and prints it. I
compare the month and the date but not the year. There is a foreach
loop
used for iteration. My script works well with the sample data that I
have
when the cgi script is run.

I use a WYSIWYG web program called "Webpagemaker." I can draw a box
then
click in it and paste my html content or script in it. I have a
limited
knowledge of cgi and html and I don`t know how to properly insert the
cgi
script into my html page. On my html page listed below, I simply
typed in
the result in the box but I want that info generated by the cgi
instead so
that it will change daily. In other words, I need to "marry" the cgi
script
to my html page.

Questions:

1) How might I achieve the aforementioned task? I have tried both <!-
-#include virtual="/cgi-bin/tips.cgi"--> and <!--#exec cgi="/cgi-bin/
tips.cgi" -->
With both I get "[an error occurred while processing this directive]"
The only thing I can come up with is maybe lycos/tripod doesn`t suport
SSI. When the site is finally finished, it will be hosted on doteasy.
com using a plan that does support SSI..

2) As a second option, I tried to put the html in the cgi page itself
and do everything from it. I get it to output on the page but I don`t
knoe how to place the outputted text where I want (see cgi file below
). Also, when I get this to work, I will have to redirect my users
form the index/html page to the cgi page. Does anyone know the proper
perl syntax to place text where you want on a page and constain it to
a selected area?

3) Also, A hard return must be used after each record in the data text
file
according to my understanding of cgi. Using my file, what if I wanted
my
last field (the tips or event field) to contain let`s say a recipe for
the
day instead of a tip for the day. The recipe would consist of more
than one
line. How could all of that be grouped together as one unit since
there
would be a hard return for each line of the recipe?

These are my files:

Html page http://dailytips.tripod.com/index.html
Datbase http://dailytips.tripod.com/cgi-bin/data.txt
Cgi file http://dailytips.tripod.com/cgi-bin/tips.cgi

Thank you in advance for any assistance you might offer me.
Reply with quote
Send private message
View user's profile Post To page top
nottherat Posted: Fri Jun 09, 2006 6:02 pm


Joined: 03 Jul 2005

Posts: 15
Need help
ckbk2002 wrote:

: 1) How might I achieve the aforementioned task? I have tried
: both <!--#include virtual="/cgi-bin/tips.cgi"--> and
: <!--#exec cgi="/cgi-bin/tips.cgi" --> With both I get "[an error
: occurred while processing this directive]" The only thing I can
: come up with is maybe lycos/tripod doesn`t suport SSI. When the
: site is finally finished, it will be hosted on doteasy.com using
: a plan that does support SSI.

While it could be set up different for your host, SSI pages
are usually delivered from files ending in .shtm or .shtml, not
.html. Many server administrators turn off the latter version (exec)
for security reasons. The error you are getting indicates that SSI
is working from this file.

You`ll need to check with the administrator as to why you are
getting an error. Though it could be that tips.cgi is throwing out
headers when it shouldn`t be or not throwing them out when it
should. Try running a simpler script for testing. Once it works,
you can try your more complex script.


: 2) As a second option, I tried to put the html in the cgi page
: itself and do everything from it. I get it to output on the
: page but I don`t [know] how to place the outputted text where I
: want (see cgi file below). Also, when I get this to work, I
: will have to redirect my users form the index/html page to the
: cgi page. Does anyone know the proper perl syntax to place text
: where you want on a page and constain it to a selected area?

You either generate the entire page from the perl script or
you use SSI to inject the output of your script into the html.
Assuming you do not have SSI, you would call a script which would
generate a properly formatted page to the calling browser. It
seems like you are having trouble with the proper formatting of
html, not with the perl part of the script, but I can`t tell
without seeing the code.

We cannot see the source of the cgi script, only its result.
Can you supply a text version of the file so we can see the actual
script?



: 3) Also, A hard return must be used after each record in the
: data text file according to my understanding of cgi. Using my
: file, what if I wanted my last field (the tips or event field)
: to contain let`s say a recipe for the day instead of a tip for
: the day. The recipe would consist of more than one line. How
: could all of that be grouped together as one unit since there
: would be a hard return for each line of the recipe?

CGI does not constrain you to using a particular record
format. It only defines an interface between a server and a
client. You can use whatever format you wish to use. Change the
format to include two hard returns of separation between records.
By setting $/ to "

" you would be able to get the recipe as one
record. (See the `perlvar` file in the docs for details.) You
could also use XML, a relational database, YAML (a perl module),
or DBM::Deep if your needs become more complicated.


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don`t tread on my bandwidth. Trim your posts.
Reply with quote
Send private message
View user's profile Post To page top
ckbk2002 Posted: Wed Jun 14, 2006 11:38 pm


Joined: 09 Jun 2006

Posts: 2
Need help
Sorry for the delay in responding. He is the original code I had for
"tips.cgi" I want the output to be located in an text box located at
left: 170px, Top: 203px with a width of 667px and Height of 397px.
Thanks.


#!/usr/local/bin/perl
require "cgi-lib.pl";

open(FILE,"data.txt") || die "Can`t find database
";
@indata = <FILE>;
close(FILE);

@Months = (`January`,`February`,`March`,`April`,`May`,`June`,`July`,
`August`,`September`,`October`,`November`,`December`);

print "Content-type: text/html

";
print "<html><body>";

($day,$month,$year) = (localtime)[3,4,5];
$year += 1900;

print "<H2 align="center" font
face="Verdana"size="2"color="#000000">Today is $Months[$month]
$day, $year</align></H2>";
print "<p></p>";


##################################################################
#foreach loop to process each record in the array
foreach $i (@indata)
{
#removes hard return character from each record
chomp($i);
#split fields on pipe character
#assign a variable name to each of the fields
($calmonth,$calday,$calyear,$event) = split(/|/,$i);
################################################################

if ($calmonth==$Month[$month] && $calday==$day){
{ print "<font face="Verdana"size="4"color="#000000">$calmonth
$calday";}
{ print "<font face="TimesNewRoman"size="2"color="#000000">
$event";}
{ print "<p></p>";}
}
}

print "</body></html>";



--- In Perl_Official@yahoogroups.com, "Charles K. Clarkson"
<cclarkson@...> wrote:
>
> ckbk2002 wrote:
>
> : 1) How might I achieve the aforementioned task? I have tried
> : both <!--#include virtual="/cgi-bin/tips.cgi"--> and
> : <!--#exec cgi="/cgi-bin/tips.cgi" --> With both I get "[an error
> : occurred while processing this directive]" The only thing I can
> : come up with is maybe lycos/tripod doesn`t suport SSI. When the
> : site is finally finished, it will be hosted on doteasy.com using
> : a plan that does support SSI.
>
> While it could be set up different for your host, SSI pages
> are usually delivered from files ending in .shtm or .shtml, not
> .html. Many server administrators turn off the latter version (exec)
> for security reasons. The error you are getting indicates that SSI
> is working from this file.
>
> You`ll need to check with the administrator as to why you are
> getting an error. Though it could be that tips.cgi is throwing out
> headers when it shouldn`t be or not throwing them out when it
> should. Try running a simpler script for testing. Once it works,
> you can try your more complex script.
>
>
> : 2) As a second option, I tried to put the html in the cgi page
> : itself and do everything from it. I get it to output on the
> : page but I don`t [know] how to place the outputted text where I
> : want (see cgi file below). Also, when I get this to work, I
> : will have to redirect my users form the index/html page to the
> : cgi page. Does anyone know the proper perl syntax to place text
> : where you want on a page and constain it to a selected area?
>
> You either generate the entire page from the perl script or
> you use SSI to inject the output of your script into the html.
> Assuming you do not have SSI, you would call a script which would
> generate a properly formatted page to the calling browser. It
> seems like you are having trouble with the proper formatting of
> html, not with the perl part of the script, but I can`t tell
> without seeing the code.
>
> We cannot see the source of the cgi script, only its result.
> Can you supply a text version of the file so we can see the actual
> script?
>
>
>
> : 3) Also, A hard return must be used after each record in the
> : data text file according to my understanding of cgi. Using my
> : file, what if I wanted my last field (the tips or event field)
> : to contain let`s say a recipe for the day instead of a tip for
> : the day. The recipe would consist of more than one line. How
> : could all of that be grouped together as one unit since there
> : would be a hard return for each line of the recipe?
>
> CGI does not constrain you to using a particular record
> format. It only defines an interface between a server and a
> client. You can use whatever format you wish to use. Change the
> format to include two hard returns of separation between records.
> By setting $/ to "

" you would be able to get the recipe as one
> record. (See the `perlvar` file in the docs for details.) You
> could also use XML, a relational database, YAML (a perl module),
> or DBM::Deep if your needs become more complicated.
>
>
> HTH,
>
> Charles K. Clarkson
> --
> Mobile Homes Specialist
> Free Market Advocate
> Web Programmer
>
> 254 968-8328
>
> Don`t tread on my bandwidth. Trim your posts.
>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help