For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > February 2005 > sorting and printing text files (was: hello all)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author sorting and printing text files (was: hello all)
Wiggins d'Anconia

2005-02-17, 3:56 pm

Don Doucette wrote:
> hello everyone.
> my name is don doucette and I am 38 years old and have been involved
> with computers since the Timex Sinclair.
>


Ok. Please use a more informative subject line.

> I have recently set up a server and am hosting a web site and forum for
> my community association.
>
> I am running the YaBB forum (http://www.yabbforum.com/) and I would like
> to do the following...
>
> I would like to use perl to look in a directory of numerical named .txt
> files (as in 0123456789.txt), find the file name with the largest number
> (as in 1234567890.txt is greater numerically than 0123456789.txt) then
> open the file and extract data from that file so it can be posted into a
> web page?
>
> For instance...
> I have a directory named Messages, in this directory there are the
> following files...
>
> 1108577587.txt
> 1108519222.txt
> 1108490078.txt
> 1108489912.txt
>
> Obviously 1108577587.txt is greater numerically than the rest, this also
> happens to signify that this is the newest message. In this file is the
> following information...
>
> Title of Post|Author|email@address.com|02/16/05 at
> 12:13:07|Group|xx|0|192.168.1.1|Message||
>
> As you can see this file is delimited by | and ends with ||
> I would like to parse out the Message field first then the Author field
> and assign their value to a variable then insert the variable into html
> on a page.
>
> Something like...
> <html>
> <head>
> <title>Untitled Document</title>
> </head>
> <body>
> <p>Here is the newest post to the forum<BR><BR>
> $Message <BR><br>
> Posted by $author </p>
> </body>
> </html>
>
> The idea is when the main web page loads it always shows the newest post
> to the forum and who posted it.
>
> My question REALLY is do you think this can be easily done or is this a
> huge programming effort for someone just trying to figure out perl... I
> have been thumbing through my Perl book (The Complete Reference Perl
> Second Edition) but it hasn't really been helpful so far.
>
> Thanks for your advice.
>
>


Clearly you have a good spec which is about the best start. In general
this is a forum for specific questions about CGI, which sort of fits,
but you might be better off with just the beginners@perl.org for non-cgi
related questions, as yours are more general. Though they are also
forums for learning, rather than getting free code so we usually like to
see what you have tried first. Having said that....

To get to your actual question, what you are talking about doing is
pretty simple in Perl. I am not familar with that particular book, if
you are interested in learning Perl you should check out the Llama from
O'Reilly, aka Learning Perl. Having read that you should be able to
solve the above problem. If you don't want more books and can read tech
docs, then you should start with,

perldoc perlopentut
perldoc -f opendir
perldoc -f readdir
perldoc -f open
perldoc -f sort
perldoc -f split
perldoc -f print
perldoc CGI

Very little is a HUGE programming effort in Perl, that is why it is so
loved by its users...

Good luck,

http://danconia.org
Don Doucette

2005-02-17, 8:55 pm

Wow the response has been great!
Thanks to everyone who threw their hat in the ring, sorry for the lousy
choice of subject line...

I am attempting to implement your suggestions, I should see a positive
result soon.

Thanks
Don



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com