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

Re: [MacPerl-WebCGI] Putting hash values in an array and checkingthat with an foreach is not working!



>Hi I have the following code snippet and it's not working properly.
>It should check the if any of the hash keys (from a POST form) is empty
>and then do the error routine.
>But it's not, it doesn't do anything of the sort.
>Is it possible to do this or is there another way besides using TEN
>if-statements.
>I may be getting this totally wrong, pls. just give me some hints.
>Yours sincerely
>Jimmy Lantz
>
>
>########## Snippet ###########
>@checks = ('$in{\'kurskod\'}', '$in{\'pnr\'}', '$in{\'fnamn\'}',
>'$in{\'enamn\'}', '$in{\'telnr\'}', '$in{\'padress\'}',
>'$in{\'postnr\'}', '$in{\'ort\'}', '$in{\'studietyp\'}',
>'$in{\'tentaresultat\'}');
>

What the heck are you doing here? Simply use

   @value_list = values %in; # 'values' and 'keys' are builtin functions,
   @key_list = keys %in;     # see perlfunc.pod
                             # RTFM - Read The Fine Manual please !

to get all the values or keys of hash %in.


>foreach $check (@checks)
>{
>if ($check eq '')
>{
>&do_error;
>exit;
>}
>}


So, putting it together:

    foreach $key (keys %in)  {
       if ($in{$key} eq '') { # tests if a value is the empty string
          &do_error;
       }#if
    }#for


Best regards

--Thomas



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org