Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
I have a webpage index.html on which i call lu.cgi.
If i try to run this script i do not see the content of msg.txt on my web
page
My web server is apache
#!/usr/bin/perl -wT
open(INFO, "/usr/lib/cgi-bin/msg.txt"); # Open db for reading and display
@array=<INFO>;
close (INFO);
print "Content-type:text/html\n\n"; #Content Header
print <<End_of_head;
<html>
<head><title>Display File Contents</title></head>
<body>
<h4>This script displays the contents of names_file.txt.</h4>
End_of_head
foreach $line (@array){
($last,$first)=split(/\|/,$line);
print <<End_of_line;
$first $last<br>
End_of_line
}
print <<End_of_Doc;
</body>
</html>
End_of_Doc
ThX
Post Follow-up to this messageIt works for me, however I put my names in file "msg.txt", not
"names_file.txt" as the program suggests.
You may also want to spit out a message if the msg.txt file doesn't exist.
"Jim roos" <Jimroos@uunet.be> wrote in message
news:RxF5c.37299$eU4.2474071@phobos.telenet-ops.be...
> Hi,
>
> I have a webpage index.html on which i call lu.cgi.
> If i try to run this script i do not see the content of msg.txt on my web
> page
> My web server is apache
>
> #!/usr/bin/perl -wT
> open(INFO, "/usr/lib/cgi-bin/msg.txt"); # Open db for reading and display
> @array=<INFO>;
> close (INFO);
> print "Content-type:text/html\n\n"; #Content Header
> print <<End_of_head;
> <html>
> <head><title>Display File Contents</title></head>
> <body>
> <h4>This script displays the contents of names_file.txt.</h4>
> End_of_head
> foreach $line (@array){
> ($last,$first)=split(/\|/,$line);
> print <<End_of_line;
> $first $last<br>
> End_of_line
> }
> print <<End_of_Doc;
> </body>
> </html>
> End_of_Doc
>
>
> ThX
>
>
Post Follow-up to this message"Jim roos" <Jimroos@uunet.be> wrote in message news:RxF5c.37299$eU4.2474071@phobos.telenet-ops.be... > Hi, > > I have a webpage index.html on which i call lu.cgi. > If i try to run this script i do not see the content of msg.txt on my web > page > My web server is apache > > #!/usr/bin/perl -wT > open(INFO, "/usr/lib/cgi-bin/msg.txt"); # Open db for reading and display You should *always*, *always* check the success of the open open INFO,"/usr/lib/cgi-bin/msg.txt" or die "Could not open msg.txt $!\n"; > @array=<INFO>; > close (INFO); Useless use of reading into an array. This valuable advice is only going to cost you $US100 plus tax. The invoice is in the mail.
Post Follow-up to this messageIn article <c38tbo$25d4h9$1@ID-172104.news.uni-berlin.de>, Tintin wrote: > >You should *always*, *always* check the success of the open Hell, you should *always* check the success of *any* system call. I check the results of syswrite, for example. You could successfully open a file in O_RDWR or O_WRONLY modes, and still fail a write due to disk quota limits or whatever else. Error checking and fault tolerance is where a LOT of amateurs and hobbyists fall short. >open INFO,"/usr/lib/cgi-bin/msg.txt" or die "Could not open msg.txt $!\n"; > > >Useless use of reading into an array. Depends on what you're doing. If one had a lot of time-intensive processing in a foreach() or while() loop, or if one needed to store it for later use, one might actually -want- to store it quickly first and process it later. It's not -always- useless. In this case, I concur though, it was patently useless. >This valuable advice is only going to cost you $US100 plus tax. The invoic e >is in the mail. My valuable additions are only going to cost the OP $75 (USD). -- Vorxion - Member of The Vortexa Elite
Post Follow-up to this message"Vorxion" <vorxion@knockingshopofthemind.com> wrote in message news:405a1a1a$1_1@news.iglou.com... > In article <c38tbo$25d4h9$1@ID-172104.news.uni-berlin.de>, Tintin wrote: > > Depends on what you're doing. If one had a lot of time-intensive > processing in a foreach() or while() loop, or if one needed to store it for > later use, one might actually -want- to store it quickly first and process > it later. It's not -always- useless. In this case, I concur though, it > was patently useless. Agree with you 100%. I was specifically commenting on the OP's code. > invoice > > My valuable additions are only going to cost the OP $75 (USD). Vorxion, the market will collapse if you are charging such cheap rates ;-)
Post Follow-up to this messageIn article <c3ei0b$26m86k$1@ID-172104.news.uni-berlin.de>, Tintin wrote: > >Agree with you 100%. I was specifically commenting on the OP's code. *nod* I knew -you- knew, I didn't know if -they- knew. :) > >Vorxion, the market will collapse if you are charging such cheap rates ;-) *chuckle* At least it's not like the Indian or Russian programmers who move the decimal point one place to the right. Then again, I just had the dubious pleasure of seeing the results of some of their work, and you get what you pay for. Coding stylistic differences aside, it looks like some of them are apparently maybe halfway through "Learning Perl" (nevermind "Programming Perl"). I basically said, "You don't want mods, you want a complete rewrite." -- Vorxion - Member of The Vortexa Elite
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.