List Hash 'Field' Names

Discussion in 'Perl Misc' started by Paanwa, Sep 10, 2003.

  1. Paanwa

    Paanwa Guest

    I am trying to write more automated code - either I am a lazy typist or am
    just trying to get more with it!

    I have a hash I define; I have a form with textboxes for each hash elements.
    When the form is submitted the user gets a chance to review their data prior
    to finalizing (writing to file).

    The form is running from the same piece of code; I would like it to use the
    hash values if it is the first time through (the hidden form object named
    cycle is set to 0), but use the submitted (either changed or left alone)
    data for the second time through - which is the 'review' part mentioned
    above (cycle is set to 1).

    I really don't want to set my form values manually:
    (summary, not actual code)
    if (param('cycle') = 0)
    {
    set Address1 = $hash{$key}{Address1};
    }
    else
    {
    set Address1 = param('Address1');
    }

    I would like to loop through the names of the hash elements like this:
    (summary, not actual code)
    foreach element_name (keys %hash)
    {
    if (param('cycle') = 0)
    {
    set form element_name value = $hash{$key}{element_name};
    }
    else
    {
    set form element_name value = param('element_name');
    }
    }

    Note: I name each form object after the corresponding hash name.

    So, can this be done?
     
    Paanwa, Sep 10, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    1
    Views:
    387
    Lucas Tam
    Jul 30, 2004
  2. rp
    Replies:
    1
    Views:
    539
    red floyd
    Nov 10, 2011
  3. Sfdesigner Sfdesigner
    Replies:
    5
    Views:
    168
    Chris Shea
    Aug 13, 2007
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    627
    David A. Black
    Jul 2, 2008
  5. Sound
    Replies:
    2
    Views:
    453
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page