[EMAIL PROTECTED] wrote:
> I'm new to Perl and am attempting a script that I found in a 
> book.

That's pretty awful code. What book is it from? You may with to consider
other options.

> You would think that it would run without modification!  :(

Though maybe some modifications would do it some good :)

> $content_length=$ENV{'CONTENT_LENGTH'};
> read (STDIN, $posted_information, $content_length);
> 
> $posted_information=~ s/%([\dA-Fa-f][dA-Fa-f])/pack ("C", hex 
> ($1))/eg;
> $posted_information=~ s/\+/ /g;
> 
> @fields=split(/&/, $form_data);

Duplicates CGI.pm functionality (but only works with METHOD=POST, not
METHOD=GET), re-inventing the wheel.

> #check email for "@"
> @check_email = split(//, $email_address);
> foreach $letter (@check_mail) {
>       if ($letter eq "@") {
>       $good_email=1;
>       last;
>       }
> }

This looks like the author had done too much C programming. And even there,
you could use strchr() -- in Perl, that reduces to '$good_email = 1 if
index($email_address, '@') > -1'. And the code you wrote is bad because it
uses a @ in a double-quoted string when it isn't interpolating an array
variable.

> #count number of digits (i.e. \d)
> @check_tel_number = split(//, $tel_number);
> foreach $number (@check_tel_number) {
>       if ($number =~ /\d/) {
>       $digits++;
>       }
> }
> 
> if ($digits == 10) {
>       $good_tel_number = 1;
> }

$good_tel_number = 1 if($tel_number =~ /^\d{10}$/);

(Aside from the fact that your code doesn't match foreign telephone numbers
because it needs exactly ten, it'll also match
"this1is2not3a4telephone5number6in7any8country9I0know" because that string
contains 10 digits....)

> if (!$good_email | !$good_tel_number) {

Nearly certainly wants '||' instead of '|' here.

>       print "<title>Invalid Data</title>\n<body>\n";
>       print "<h2>Invalid Data</h2>\n";
>       print "<p>You have entered invalid data in the form.  
> Please correct \n";
>       print "the data in the fields with red labels.</p>\n";
>       print "<form action=\"dosurvey.cgi\" method=post\n";
>       print "<table border=0>\n<tr>\n<td align=right>User 
> name:</td>\n";
>       print "<td><input type=\"text\" size=40 maxsize=60 
> name=\"user_name\"
>               value=\"$user_name\"></td>\n</tr>\n";

Lots of backslashing \" and separate prints where a here-document would have
been a lot nicer:

   print <<END;
<form action="dosurvey.cgi" method="post">
<td><input type="text" size="40" maxsize="60" name="user_name"
value="$user_name"></td>
</tr>
END

sort of thing. You get the idea.

Cheers,
Philip

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to