BVA> I have written a tutorial and would like to suggest a couple of
BVA> good Perl related books. But since I have little knowledge of
BVA> perl books, I have to come to you for aid. Would you recommend
BVA> some good books for a perl beginner.
odd to have written a perl tutorial but not to have read any decent perl
books. what did you use to teach yourself perl?
BVA> The said tutorial is available at
BVA>
http://www.geocities.com/binnyva/code/perl/tutorial/index.html
BVA> If you have any comment or suggestions about that tutorial, please
BVA> send it to me or post it in this group.
have you searched the web for other tutorials? have you noticed how bad
most of them are? i have read many and less than a handful are accurate
and well written.
ok, let's start with some quick comments.
you have done the common mistake of emphasizing perl is for cgi whereas
most perl coding is not cgi. shell programming is done with shells like
bourne, bash, etc. perl coding is NOT shell coding.
you do not need a 'server' to run perl scripts. that is cgi-centric
again which is wrongheaded.
most unix/linux platforms have perl but in many cases it is an outdated
version so recommending to install a fresh one would be a good idea.
you don't need syntax highlighting to edit perl. any decent text editor
will do.
1) The #!/usr/local/bin/perl line. Put this in the most top of the
file. Line No 1. What does it do? You sure you want to know? Well it
tells the server that is running the script the locaiton of perl. Now
there is a problem here. Some servers have perl in a different
location. So you have to find where the perl is located in your
server. Sometimes it will be #!/usr/bin/perl. Now if you are using
ActivePerl in Windows, the script will run without this line. But
just put it in anyway. Make it a habit.
again, perl does NOT NEED a server to run. stop saying that. and that
line is NOT perl syntax or anything to do with perl. it is a function of
unix and how it handles script files of which perl is just one type of
many.
3) Include as many comments as possible. One of the most noted
disadvangtages of perl is it bad redability. So if you want to
understand what you wrote today when you read it tommarow, you'd
better put comments where ever you can. Comments can be inluded with
the '#' charector. Rather harsh, don't you think? Sorry about the pun
- could'nt resist. This is the example of a comment...
# This is a comment
print "Hell World"; # Everything after the '#' is a comment
spellchecking would help a great deal. that paragraph is
unreadable. maybe some comments would help? as for including plenty of
comments that is misleading. bad code can be written in any language and
all code needs commenting. rule: code is what, comments are why.
and if your world is hell, then i am not sure i want to read your
tutorial.
6) Variables are words which has the '$' symbol at the start. They need
not be declared. But if you want a local scope varible use the
keyword 'my'. You can learn more about variables later.
bah!! use strict is important and it requires variables to be
declared. and calling lexical scope 'local' and mentioning 'my' is
extremely confusing as there is a 'local' declarator as well.
The second line shows how to output stuff. But what if we want
to get user input? $var = ; This statment will get data from
"Standard Input"(Keboard) and store the data in a variable
called '$var'. Please not the STDIN must be in capital letters.
where did <STDIN> go? it is in the html source. you should know to
encode < and > as entities.
The 'my' keyword can be used if you want a local variable. Don't
know what a local variable is? That's bad. Local variable is the
variable that exist only in the block that it is defined in.
that is so badly written and misleading.
in the operators section you show all the numeric comparison ops but
only eq and ne for strings.
you keep trying to make jokes but they are flat and inappropriate. stick
to accuracy and better writing first.
For Loop
This has been for long the favorite loop of many programmers I
know. For, what wouldn't a programmer give for for.
Syntax
for(initialization ; condition ; next) {
body
}
most decent perl coders rarely use c style for loops. foreach loops are
generally what is wanted as they are usually cleaner, faster and more
direct. but you haven't learned that yet it seems. funny how most
perl tutorial authors on the web don't know perl that well. they learn
some, get to like it and think they should help others but they don't
have the proper skills to write a quality tutorial.
sub plus
{
....
}
No Arguments! Does that mean that perl can't pass arguments? No,
it don't. The arguments of perl are stored in an array '@_'. Now
you will be asking what is '@_'. This is a predefined variable
in perl. These things have special meaning to perl. For example,
$_ will be used to store the arguments and default input. $!
will be used for error codes. There are many more predefined
variables in perl. As a matter of fact, most of the punctuation
has special meaning for perl. In this case, @_ stores the
arguments passed to the subroutine.
there is the usual misinformation about $_. why not at least point the
reader to perldoc perlvar? in fact you should always be referring the
reader to the perl docs for more (and accurate) info.
Wow! Three lines of code, Two pages of explanation. Sometime I
amaze even myself.
you amaze me all the time. terseness is a good writing skill to
learn. you cover so little of perl in so much verbiage.
#Get the input
if ($ENV{REQUEST_METHOD} eq 'POST') {
read(STDIN, $query_string, $ENV{CONTENT_LENGTH});
} else {
$query_string = $ENV{QUERY_STRING};
}
ok, that is the last straw. do you not even know about CGI.pm? do you
not realize the problems and bugs that homemade cgi parsers have?
and this straw breaks the camel's back.
Some places where great Perl Scripts are available...
http://www.geocities.com/binnyva/code/perl/ My own collection of Perl scripts that I wrote over the ages
http://cgi.resourceindex.com/ A huge collection of CGI Resources. CGI programs in perl and other languages.
http://www.scriptarchive.com/ Matt's Script Archive. Offering free CGI scripts to the web community
matt's scripts are an unholy mess and even he says that.
and i took a gander at your guestbook script. it has too many bugs and
too much bad code to even review. i will leave that to any others here
if they want the fun and glory.
i hope you had fun with this feedback and take it the right way. it
wasn't fun for me as i had to wade through another poor perl tutorial by
another self taught cgi kiddie. please get a some good books on perl and
study them as you have much to learn. using strict and CGI.pm are
probably the first things.
uri