Old tutorial - now corrected

B

Binny V A

I am the author of the "Beginner's Tutorial for CGI
Perl Language" at
http://www.geocities.com/binnyva/code/perl/tutorial/index.html
This is a tutorial for the perl language. Teaches how
to develop CGI(Common Gateway Interface) perl programs
for websites.

It was the subject of a few posts a couple of months ago -
http://tinyurl.com/3l2t2

I believe that I have corrected all the problems that
were pointed out in those posts. Anyone interested can
take a look at it. If you notice any more errors, please
let me know. I certainly expect to find some after
seeing the results of my previous attempt. After all
that is debugging - taking out old bugs and putting
in new ones. ;-)

PS : Sorry about the delay in repairing the tutorial.

Thank You,
Binny V A
http://www.geocities.com/binnyva/code
 
A

A. Sinan Unur

(e-mail address removed) (Binny V A) wrote in
I am the author of the "Beginner's Tutorial for CGI
Perl Language" at
http://www.geocities.com/binnyva/code/perl/tutorial/index.html ....

It was the subject of a few posts a couple of months ago -
http://tinyurl.com/3l2t2

I believe that I have corrected all the problems that
were pointed out in those posts. Anyone interested can
take a look at it. If you notice any more errors, please
let me know.

OK. I'll bite. You know, you could make it much easier for people to
comment if we could just see the source code on your site rather than
having to download a zip and extract the source etc etc.

My comments pertain to:

# Name Of Script : Message Board
#
# Version : 1.00.A

First thing I noticed is that there is still no

use strict;

That is kind of obnoxious of you.
# Set Variables
$file = "message_board.html"; # The File where the message
board is displayed
$messagesfile = "messages.html"; # The file that stores all the
messages
$seperator = "-"; # Date sepeator (9'-'10..)

First off, do away with useless right margin comments such as these.
Second, the word is spelled 'separator'. Third, you are better off using
a hash for this sort of thing:

my %config = (
board_file => 'message_board.html',
messages_file => 'messages.html',
date_separator => '-',
);

Now, the kicker:
# Get input
my $value;
if ($ENV{'REQUEST_METHOD'} eq "GET")
{
$value = $ENV{'QUERY_STRING'};
}
else
{
$value = <STDIN>;
}

Oh, get ready for fun CGI parsing ...

use CGI ':standard';
$CGI::pOST_MAX = 100*1024;
$CGI::DISABLE_UPLOADS = 1;
# Take time to make things happen
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
(time);
$year = $year - 100;
$mon++;
$date = "$mday$seperator$mon$seperator200$year";

It looks like you still haven't read the responses to your original
postings. Neither have you bothered to look at

perldoc -f localtime

What if the year is 2014? Then, $date above will be set to
"26-1-20014". Do you think that is correct? If so, you are even more
dimwitted than I give you credit for.

Encapsulate this in a sub:

sub formatted_date {
my $separator = shift;
my ($mday, $month, $year) = (localtime time)[3, 4, 5];
sprintf('%2.2d%s%2.2d%s%4.4d',
$mday,
$separator,
++$month,
$separator,
1900 + $year
);
}

I cannot remember the name of the module on CPAN that deals with
formatting dates according to the RFC whose number I cannot remember
(here is an idea, why don't you search CPAN yourself and find the
appropriate date formatting module?)
# Making the input English. And removing unwanted things

WTF does this mean? What if I posted something in Turkish on this site?
Have you written a translator for Turkish -> English that Google does
not know about?
$value =~ s/%(..)/pack("c", hex($1))/ge;
$value =~ s/comments\=//gi;
$value =~ s/\+/ /gi;
$value =~ s/\n/<BR>/gi;
# Catogarizing the input

Speaking of English ...
@value = split(/&/, "$value" );
$comments = $value[0];

Please do everyone a favor and use CGI.pm.
# Open Guest Book File
open (FILE, "$messagesfile") ||

Useless use of quotes. See

perldoc -q always
print "Can't open $messagesfile: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

We have been through this once before. You try to open a file. If there
is an error, you print something and continue on to read lines from the
file that you failed to open.

Finally, I urge everyone to stay away from scripts that allow people to
write arbitrary amounts of data to your server's hard drive. Please.

Sinan.
 
B

binnyva

Most of the programs there are very old relics - about
two to three years old - I am too lazy to update them.
I should do that - I know. Maybe sometime this year...

Anyway the subject is the tutorial - not my old scripts.
Thank You,
Binny V A
http://www.geocities.com/binnyva/code
 
T

Tore Aursand

Most of the programs there are very old relics - about
two to three years old - I am too lazy to update them.
I should do that - I know. Maybe sometime this year...

Anyway the subject is the tutorial - not my old scripts.

Aren't the scripts _a part of_ the tutorial?
 
A

A. Sinan Unur

The line between being critical and being needlessly abusive is not
fine by any means. You have managed to cross it anyway.

I agree that the last sentence of that paragraph was completely
unnecessary and indeed my point would have been better made had I had
the sense not to post that. I apologize.

On the other hand, please take a look at:

<http://groups-
beta.google.com/group/comp.lang.perl.misc/msg/ec9bf41c19ec1b40>
(<http://tinyurl.com/4gyfy>)

and compare it to my comments this time.

The OP claimed that he had read the comments and made changes to take
those comments into account. Upon reading his code again, I did not
think he had actually done that at all.

Elsethread, the OP has claimed that the code I commented on was not part
of the tutorial. I am not able to figure out what is and what is not a
part of the tutorial. I simply followed the link he posted. There was
some stuff about men and cowards and LOC etc and some links listed on
the left. So, I followed one of those links, specifically, the one that
said 'Perl'.

Going back, I now see a link titled "Next" on the page. I did not see
that originally.

To bring up the usefullness quotient of this thread a little, I am going
to recommend "Picking up Perl" to anyone who is looking for an
introductory Perl tutorial:

http://www.ebb.org/PickingUpPerl/

Actually visiting:

http://learn.perl.org/

and seeing what is available to new users would also not be a bad idea.

Sinan.
 
T

Tad McClellan

Most of the programs there are very old relics - about
two to three years old - I am too lazy to update them.


It would take about 20 seconds to remove the links to them.
 
A

Anno Siegel

Bernard El-Hagin said:
The line between being critical and being needlessly abusive is not
fine by any means. You have managed to cross it anyway. You do so on a
regular basis. It was uncalled for in this case and is uncalled for
almost every time you stoop to it.

Then again, a "tutorial" that introduces its very own Y2010 bug, in a
revised edition, no less, must be considered beyond redemption. Strong
discouragement is indicated.

Anno
 
A

Anno Siegel

Most of the programs there are very old relics - about
two to three years old - I am too lazy to update them.
I should do that - I know. Maybe sometime this year...

Too *lazy*? In publishing your Perl pages, tutorial, scripts, whatever,
you have taken on an obligation to maintain them according to your best
knowledge.

You are doing the Perl community a disservice. Take them down.

Anno
 
B

binnyva

The scripts are not the part of the tutorial - at the end of the
tutorial I gave some sample CGI scripts by giving links to my
collection at http://www.geocities.com/binnyva/code/perl/ and to CGI's
other resource sites like http://cgi.resourceindex.com/ and
http://www.scriptarchive.com/.
A link in a tutorial does NOT makes the target file a part of the
tutorial - I almost hope it would - then http://cgi.resourceindex.com/
would be a part of my tutorial.
Can we concentrate on my tutorial, please?
 
B

binnyva

I admit that I should correct those scirpts - I will.
But please not that those are functional scirpt -
just not perfect. They have some bugs. The most
noted problem was that I did not use CGI.pm
module. One should remember that not everyone
has the CGI.pm module. They should be having it -
but its not a perlfect(sic) world.

But I promise that I will correct the bugs as soon
as possible.

Thank you,
Binny V A
http://www.geocities.com/binnyva/code
 
A

Anno Siegel

I admit that I should correct those scirpts - I will.
But please not that those are functional scirpt -
^^^
That must be a Freudian slip. They're probably as functional as M*tt's
Script Archive.

If the bit of date manipulation code that was shown here is any indication,
you are *way* too inexperienced in Perl, and programming in general, to be
publishing code. Stop it.

Anno
 
A

Alan J. Flavell

The scripts are not the part of the tutorial

Look, give it a rest already. You're quite dangerous to be let loose
on beginners, but you don't seem to want to recognise the fact.

If you /really/ took the advice you're getting here, you'd take that
stuff off the web for the time being. But you seem to be deaf to that
part of the advice (and to too much of the rest too). I suppose all
we can do is offer a "c.l.p.m health warning" and hope that it'll
reach at least some of your intended audience.

Don't take this wrong - we all have to start somewhere, and there's no
shame in being a beginner - but that doesn't mean rushing right out
and publishing a premature tutorial.
 
T

Tad McClellan

Can we concentrate on my tutorial, please?


That would be a waste of effort.

You are not qualified to do what you are doing, please
stop doing it.


No code is *better* than bad code!
 
A

A. Sinan Unur

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
The scripts are not the part of the tutorial.
....

Can we concentrate on my tutorial, please?

I am assuming
http://www.geocities.com/binnyva/code/perl/tutorial/cgi_perl.html is
part of your tutorial. There, you discuss at length your guestbook
script as an example of how to do CGI programming in Perl.

All code below are from the URL given above.
Now lets get the input...

my $query_string = "";
#Get the input
if ($ENV{REQUEST_METHOD} eq 'POST') {
read(STDIN, $query_string, $ENV{CONTENT_LENGTH});

read can fail, you know.
} else {
$query_string = $ENV{QUERY_STRING};
}
##### We will remove this
print "Content-Type: text/html\n\n";
print "Query String is \n<br> $query_string";
##### We will remove this

Why do you claim to be returning HTML when you are not?


The data will be in this format -
<Input name>=<Inputted Data>&<Next Input name>=<Next Inputted Data>
and so on

So, you are not going to handle:

http://www.example.com/cgi-bin/test.pl?field1=One;field2=Two
Now add the following lines to the guestbook.pl file...

# Split the name-value pairs
@pairs = split(/&/, $query_string);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

# Making the input English. And removing unwanted things
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}

You just copied and pasted this block of code without understanding what
it does. You are recommending to beginners that they do the same. There
is no point to doing this in a beginners' tutorial. You should just use
CGI.pm. Then, if anyone wants to hand-parse CGI, they can look at the
source code for CGI.pm to learn how to do it properly. That would be
useful for you as well.

Oh, and don't claim that some people may not have CGI.pm. Any Perl
installation that does not have CGI.pm is broken.

But, of course, the real kicker is:
For a better guest book program that I have created, go
to http://www.geocities.com/binnyva/code/perl/cgi/guestbook.html.

I would say this kind of reference does indeed make the scripts part of
your tutorial.

Anyway, I think I have had my fill of this.

Sinan
 
E

Eric Bohlman

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
I admit that I should correct those scirpts - I will.
But please not that those are functional scirpt -
just not perfect. They have some bugs. The most

Most people with any experience in programming wouldn't consider
"functional" to be a useful way of saying "works only when conditions are
just right." A "functional" program works properly regardless of the
phase of the moon or the particular variety of goat you sacrifice.

The big issue here is your intended audience. By definition, a beginner
in any subject is someone who doesn't know enough about that subject to
be able to tell bad examples apart from good examples. Therefore, anyone
who writes a tutorial really, really, needs to make sure that all their
examples are as close to perfect as is humanly possible. If you present
beginners with half-assed examples, they'll internalize them and that
will put a big stumbling block in front of their future learning. It's
*much* harder for someone to unlearn The Wrong Way To Do It and
subsequently learn the Right Way To Do It than it is to learn the Right
Way from scratch.

You should make every possible effort *not* to expose beginners to
example code that contains bugs except as part of efforts to teach them
how to recognize bugs.
noted problem was that I did not use CGI.pm
module. One should remember that not everyone
has the CGI.pm module. They should be having it -
but its not a perlfect(sic) world.

CGI.pm has been part of the default Perl distribution for at least 7
years. Therefore, if someone doesn't have it, either they haven't
updated their Perl distribution since the mid-90s or they didn't install
the distribution properly. Under such circumstances, learning any aspect
of Perl programming is going to be unnecessarily difficult.
 
B

brian d foy

Eric said:
(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
Most people with any experience in programming wouldn't consider
"functional" to be a useful way of saying "works only when conditions are
just right.

Indeed, "functional" means something different than
"functioning" or "working". :)
 
B

binnyva

Not everybody said that I have to junk my tutorial.
Two or three persons said that - the majority said that I
have to improve the tutorial. Anyway even if everyday
would have asked me to trash the tutorial, I would not
have done so. Come on guys, we are programmers - if we
see a lot of errors when we first run a new program, do
we scrape the project or do we correct it? Thats what I
am trying to do.

Binny.
 
P

Paul Lalli

Come on guys, we are programmers - if we
see a lot of errors when we first run a new program, do
we scrape the project or do we correct it? Thats what I
am trying to do.

But in the *meantime*, you are displaying faulty code allegedly
intentioned to help new programmers. Professional programmers do NOT
release code they know to be buggy *before* repairing it. It is not
good enough to say that you'll eventually fix it, all the while allowing
the possibility of some unsuspecting newbie finding and attempting to
learn from it. That is, I believe, what most people are complaining
about.

Paul Lalli
 
A

Anno Siegel

Not everybody said that I have to junk my tutorial.
Two or three persons said that - the majority said that I
have to improve the tutorial. Anyway even if everyday
would have asked me to trash the tutorial, I would not
have done so.

Then why did you ask our opinion?
Come on guys, we are programmers - if we
see a lot of errors when we first run a new program, do
we scrape the project or do we correct it? Thats what I
am trying to do.

"We" don't publish every brain fart on the web. That's what you're doing,
and it's wrong.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top