Google Answers Logo
View Question
 
Q: Perl Script for reading a flat file and displaying as HTML ( No Answer,   1 Comment )
Question  
Subject: Perl Script for reading a flat file and displaying as HTML
Category: Computers > Programming
Asked by: phillycaferacer-ga
List Price: $75.00
Posted: 06 May 2005 13:50 PDT
Expires: 05 Jun 2005 13:50 PDT
Question ID: 518623
HellO;

I need a perl script for reading a flat file (text tab) and displaying
as a formatted HTML calendar.  The flat file starts "appointment name", "begin
date, time", "end date, time" and a "public" field.  You could change
the file into a hash file so the script could run a for each loop on
the file and split the appointments into variables.

You could start with something like this... 

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

ReadParse(*input);
$datetosearch = $input{'showdate'};
$showthisdate = substr($input{'showdate'}, 0, 2);
$showthisdate1 = substr($input{'showdate'}, 2, 2);
$showthisdate2 = substr($input{'showdate'}, 4, 4);
$appointment = $input{'appointment'};
$a = $appointment

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$thismonth = $mon + 1; # month in perl is 0-11, must add 1
$thismonth1 = (Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec)[$mon];
$year = $year + 1900; # After year 2000, year comes in form 
# 100 = 2000, etc. So this works
if ($thismonth < 10)
{ $thismonth2 = join ', 0, $thismonth; }
else
{ $thismonth2 = $thismonth }

if ($mday < 10)
{ $thisday = join ', 0, $mday; }
else
{ $thisday = $mday; }

$time0 = (join ', $thismonth2, $thisday, $year);

Request for Question Clarification by studboy-ga on 06 May 2005 16:02 PDT
Hi phillycaferacer-ga 

Can you elaborate a little on the HTML calendar outout?
Do you have a sample by chance?

Thanks

Clarification of Question by phillycaferacer-ga on 06 May 2005 18:24 PDT
Hi:

Here's an example -
http://www.jayeckles.com/cgi-bin/calendar2/index.cgi?month=7&year=2005&db=calendar.db

Very simple html interface in the "month view".  URL's for appointment
details could link to a target frame within the same page or on a
separate page as in the example above.

The biggest thing for me is the use this flat file for my data file
for the calendar.  Its in this format, "appointment description" tab
"start date and time" tab "end date and time" tab "private/public
designation".

Request for Question Clarification by studboy-ga on 07 May 2005 13:49 PDT
Hi phillycaferacer-ga 

OK, I looked thru and analyze what you have, I've some suggestions:

1) You are attempting to modify the addevent.cgi file to read in a text file.  
I think this is not the correct place to do so--
if you look in index.cgi, line 109:

%calendar = %dnfunc::database;

All you need is replace that with:

%calendar = parsetextfile("yourapptfile");

I can come up with the parsetextfile()function for you, let you know
if this is what you want and can proceed quickly.  Thanks.

Clarification of Question by phillycaferacer-ga on 07 May 2005 14:48 PDT
studboy-ga:

I guess what I'm going for is even less complicated than that example
link I had sent earlier - a virtually static webpage with the calendar
information display, no ability to add apointments, only to be able to
view them. Would be too much trouble to remove this functionality and
write the parsetextfile() function?

Request for Question Clarification by studboy-ga on 07 May 2005 16:21 PDT
Not a problem.  You can remove the add/edit events by removing lines
133, 252, 281 from view.cgi.  I will proceed with parsetextfile()
function and post it as soon as I have it done -- do you need it by a
certain time frame?  I 'd estimate a couple of days.  Thanks.

Clarification of Question by phillycaferacer-ga on 07 May 2005 18:38 PDT
Ok sounds good.  Tuesday morning EST?

Request for Question Clarification by studboy-ga on 07 May 2005 20:32 PDT
Sure, Tuesday sounds good.  BTW, can you post (or point me to) a small
(sample) yourapptfile?  I know it's tab delimited so it's a bit
difficult to post here but I just want to get an idea so I can test it
before posting the answer.  Thanks.

Clarification of Question by phillycaferacer-ga on 07 May 2005 21:30 PDT
If you supply an email address I can send you a small sample.

Request for Question Clarification by studboy-ga on 08 May 2005 01:58 PDT
Thanks phillycaferacer-ga.  However, Google Answers has strict policy
against me posting offline emails--I think it's best if you post it
here (I just need a couple of lines from the file).  Thanks!

Clarification of Question by phillycaferacer-ga on 08 May 2005 08:33 PDT
Ok -
here's the file
http://www.isaiahcampbell.com/CalendarSample.txt

Request for Question Clarification by studboy-ga on 09 May 2005 01:27 PDT
OK, there are some slight problems with CalendarSample.txt--

1) The tabs are not consistent throughtout--sometimes you have 2 tabs
between the fields, and sometimes you have 1--is it possible to make
that file as consistent as possible?

2) The fields themselves are not consistent--
line 1 has one date, then 2 times.
line 6 has two dates, no time.
Can the fields be defined as consistently as possible?
Either use the tabs correctly to delimited a "blank" fields,
or we need a place holder to denote the blank field.



As it turns out, the DB in the link you posed is used in several
pieces of the code.  It turns out the best thing for the
parsetextfile() function to do is to convert CalendarSample.txt into
calendar.db, then proceed accordingly.


For a first pass of the code, can we simplify the multi-date appts?
ie, can we just print them out once on the start date?  It turns out
it's pretty tricky to print it across several dates.  We can certainly
enhance it later.  Thanks.

Clarification of Question by phillycaferacer-ga on 09 May 2005 02:06 PDT
Check this out: http://www.isaiahcampbell.com/team3calendar.txt

Request for Question Clarification by studboy-ga on 09 May 2005 03:31 PDT
Isn't that the same as what you first posted?  Why did you pointed me
to the second version then?  Also, isn't that already what you're
looking for?  I don't understand what else do you need.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Perl Script for reading a flat file and displaying as HTML
From: bozo99-ga on 06 May 2005 19:09 PDT
 
It sounds as if you want to use HTML tables.
You can bung links (<a href="foo">bar</a>) into table cells.

Your Perl is not totally idiomatic.
  $year += 1900; # save a few chars in an addition command
  printf("%02d", $month);  # print 2-digit number with leading 0 if needed

A tip I find useful is to remember double-quote is ASCII 34.
This means you can print double-quotes for your HTML in Perl code like:
    printf("%c%s%c\n", 34,$text,34);

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy