[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03744] Re: CGI module and form fields values

From: Dave Thomas <Dave@...>
Date: 2000-07-02 16:11:12 UTC
List: ruby-talk #3744
Jilani Khaldi <jilanik@tin.it> writes:

> running this code:
> ..
> cgi = CGI.new
> h = cgi.params
> h.each_key {|key| print key, "<br>"}
> ..
> How to get in output the fields and their value in the same order as
> they are in the form?

A hash is not ordered, so you won't be able to have 'each' return the
fields in any particular order.

A solution might be to give each field a name that includes a prefix:

  A_name
  B_address

or

  00_name
  01_address

Then you can sort the set of keys before processing them:

   h.keys.sort.each do |key|
     ...
   end


Regards


Dave

In This Thread

Prev Next