in reply to Re: Key/Value Problem
in thread Key/Value Problem

That makes sense to me, and I appreciate the input. Can you show me an example of how I would add a field list and then iterate through them, presumably with a foreach loop. Thanks

Replies are listed 'Best First'.
Re: Re: Re: Key/Value Problem
by suaveant (Parson) on Apr 19, 2001 at 18:34 UTC
    Sure... make an array of names...
    @fields = ('required-name','age'); # etc etc etc foreach $sortedkeys (@sortedkeys) { $sortedkeys =~ s/^\d*\)\s*//; $sortedkeys =~ s/required-//; ($name, $answer) = split (/\|/, $sortedkeys); $form{$name} = $answer; } #so now all your data is in a hash, keyed off the name. foreach $field (@fields) { #check if form value exists, if yes, put form value in #$answer, otherwise put a comma? $answer = (exists $form{$field} ? $form{$field} : ','); print FORM "$field -- $answer\n"; }
    That make sense?
    They will print in the order you put @fields in.
                    - Ant
      Thanks so much for your insights. The code you propose makes sense, but whenI run it with my form, it doesn't seem to actally get any of the answers provided. I created the @fiels array using the names that I use in the form (i.e. 'name','01','02','03' etc....). In my form, I have about 20 different elements that are radio button choices, so for question 2 it might be something like:
      <input type="radio" name="02" value="a"> Required in my major </td> <td> <input type="radio" name="02" value="b"> Required, not in my major </td> <td> <input type="radio" name="02" value="c"> An Elective </td>
      When the user picks the third option (value="c"), then I want that to show up for the value of field (name) "02". If they don't choose any of the options, then it will be a comma. When I test the code you suggest, I get a comma for every answer, whether I selected anything or not. Any ideas? I really appreciate all the information as I wade through this.
        print out $name before you put the value in the hash... does it look right?

        repost your new code... maybe its something simple...
                        - Ant