On Aug 17, awards said:

>I have many forms, and basically I just need to receive either a number
>or characters or both. this is how I check

To answer your subject line, YES, it is a good idea to verifying the data
a user sends you is what you expect.

>my ($value,%result,$name);

$value and $name should be declare inside the loop, since that's the
extent of their scope (as far as this code shows).

>foreach (param){
>    $name = $_;
>    $name =~ s/\s$//;##take the space at the end
>    $name =~ s/[^a-zA-Z0-9]//g;##all none character is change into nothing

Why are you bothering to do anything to the NAME of the field?  You
created the names of the form fields (right?), and besides, you don't end
up using $name.

>    $value = param($_);
>    $value =~ s/\s$//;## take the space at then end
>    $value =~ s/[^a-zA-Z0-9]//g;##all none character is change into nothing

Why do you remove the space at the end if you're going to be removing all
non-letters-and-numbers anyway?  A space would be deleted anyway.

>    $result{$_}=$value;
>}

Finally, why are you using a hash?  Why not just store the values back
into param()?  If you're dealing with a form that has checkboxes, or
multiple fields with the same name, you'll lose some data your way.

  for (param) {
    my @values = param($_);
    tr/a-zA-Z0-9//cd for @values;  # a faster way
    param($_, @values);  # this SETS the values of the param to @values
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to