ReadParse() and Hash values order

176 views Asked by At

I am trying to read values from form using ReadParse() function in Hash (%in), I am not getting elements as order I submit in form, I Want get in same oreder as I submit in form, please give me solution. Thanks.

2

There are 2 answers

1
spazm On

Hash keys/values are not stored in the order they are added.

What are you trying to accomplish? Perhaps there is another way?

I didn't realize that the order is specified in the HTML spec:

application/x-www-form-urlencoded

This is the default content type. Forms submitted with this content type must be encoded as follows:

  1. Control names and values are escaped. Space characters are replaced by '+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by '%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., '%0D%0A').
  2. The control names/values are listed in the order they appear in the document. The name is separated from the value by '=' and name/value pairs are separated from each other by '&'. [http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4]
0
mpapec On

Check perldoc CGI FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT:

my @names = $query->param;

As of version 1.5, the array of parameter names returned will be in the same order as they were submitted by the browser. Usually this order is the same as the order in which the parameters are defined in the form (however, this isn't part of the spec, and so isn't guaranteed).