in reply to CGI.pm - multiple values for same field name

Hi,

Thanks! it worked!

I will review more about slicing and accessing elements from a list. I was not familiar enough with the terms, so it was hard researching fro an answer.

Anyhow, the only reason I wanted to access the list this way was because theres about 10 fields with the same field names and all fields are optional.
  • Comment on Re: CGI.pm - multiple values for same field name

Replies are listed 'Best First'.
Re^2: CGI.pm - multiple values for same field name
by ikegami (Patriarch) on May 25, 2007 at 06:17 UTC
    The differences between slicing and indexing are very minor.
    Array Indexing -------------- SCALAR = $array[SCALAR EXPR]; $value = $array[5]; Array Slicing ------------- LIST = @array[LIST EXPR]; @values = @array[5,6,7]; $value = @array[5,6,7]; # Prev same as: $value = $array[7]; Hash Indexing ------------- SCALAR = $hash{SCALAR EXPR}; $value = $hash{'apple'}; Hash Slicing ------------ LIST = @hash{LIST EXPR}; @values = @hash{'apple', 'orange'}; $value = @hash{'apple', 'orange'}; # Prev same as: $value = $hash{'orange'}; List Slicing ------------ LIST = (LIST)[LIST EXPR]; @values = (split(/,/, 'a,b,c,d'))[1,2]; $value = (split(/,/, 'a,b,c,d'))[1,2]; # Prev same as: $value = (split(/,/, 'a,b,c,d'))[2];
Re^2: CGI.pm - multiple values for same field name
by naikonta (Curate) on May 25, 2007 at 07:30 UTC
    Anyhow, the only reason I wanted to access the list this way was because theres about 10 fields with the same field names and all fields are optional.
    But, why are you interested only in a specific value of the fields? If one has some fields with the same name, usually those field are:
    • Radio button, this allows user to select an option and only the value of the selected option will be sent to the server. In this case, $INPUT->param('fieldname') will return exactly one value.
    • Checkbox, this allows user to select more than one options and the values of selected options will be sent to the server. In this case, $INPUT->param('fieldname') will return more than one values.
    (Another case where $INPUT->param('fieldname') will return multiple values if the field type is select and multiple is true).

    So, if you know that you will get more than one values, why you're only interested in the particular value (from your example, the sixth element of the array)? If it wasn't a multiple <select> or <input type="checkbox"> field, say, a number of textfields with the same name, than there might be something wrong with your form design.


    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!