Tom Joyce on Fri, 10 Dec 1999 20:41:53 -0500 (EST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [Plug] Learning Perl


My first PERL book was Teach Yourself Perl 5 in 21 days by Sams Publishing
Second edition. There may be a newer one out now. As a beginner these types
of books help and explain things in an easy to understand way. In the end
you will want to buy the camel book. {Programming Perl by O'Reilly}

I have found that what I wanted to do was web cgi perl programming.

Both of which were hard to figure out for a beginner, at the time, from
either book.

A easy to learn basics site on the web is
http://www.lightsphere.com/dev/cgi.html
There are links to resources also.

The below lines are from a script in matts script archives:
http://www.worldwidemart.com/scripts

#!/usr/bin/perl
print "Content-type:text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}

In the beginning I had no clue what it meant but it allowed me to make cgi
scripts accepting input from forms on the web.

For example make a form with two fields named a and b.
Enter a value in a and b and click submit and the following program will add
the values and print them to the screen in a web browser
 .

#!/us/bin/Perl
print "Content-type:text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}

$a = ($FORM{'a'});
$b = ($FORM{'b'});

$answer = ($a + $b);

print $answer;

Here is the complete HTML form to use with the script:
<HTML>
<HEAD>
 <TITLE>Add it Up</TITLE>
</HEAD>
<FORM ACTION="additup.cgi" METHOD="POST">
<P><INPUT TYPE="TEXT" NAME="a" SIZE="5"><BR>
<INPUT TYPE="TEXT" NAME="b" SIZE="5"><BR>
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Add it up">
</FORM>
</BODY>


Tom



>What's the best book to learn Perl for a beginner?



_______________________________________________
Plug maillist  -  Plug@lists.nothinbut.net
http://lists.nothinbut.net/mail/listinfo/plug