Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    forcing hashed params to output in a set order.

    Hi.

    I have passed a load of params from a form to this script. This script will check them for cleanliness and I want the erroneous values to output in the same order as in the previous form.

    This is what I am trying but I have a sneaking feeling that I am making it loop through all the values each time it tries to output any one. Am I correct or os this the correct way to do this?

    Code:
      my %params = $cgi->Vars;
      my @acceptable_input = acceptable_values(); 
      my %valid_keys;
    
      foreach my $key ( keys %params ) # loop through all sent params
      {
     
        foreach my $column_name(@acceptable_input)
        {
        my ($field, $label) = each %$column_name;
        $valid_keys{$field} = $field;
       
          if ($key eq $valid_keys{$field} )
          {
          print qq( OK );
          }
    
        }
    
      }

    bazz
    Last edited by bazz; 08-04-2009 at 05:45 AM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Here's where I have got to.

    Code:
      foreach my $column_name(@acceptable_input)
      {
      
        my ($field, $label) = each %$column_name;
        $valid_keys{$field}=$field;
        $ok = $valid_keys{$field};
    
        if ($key eq $ok )
        {
          
          if ($key eq 'title')
          { 
          print qq( title = $key );
          }
    
        }
      }
    This is as far as I have got. I need a reminder on how to make the next 'ifs' run in the order of the array at @acceptable_input.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    ah, got it. I had my loops in the wrong order.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #4
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    You can get the params as an array and loop over the array to preserve order. See the CGI documentation.

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Quote Originally Posted by KevinADC View Post
    You can get the params as an array and loop over the array to preserve order. See the CGI documentation.
    Yes, but...AFAIK the order is based on the tabindex setting which may or may not be in the desired order.

  • #6
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    Quote Originally Posted by FishMonger View Post
    Yes, but...AFAIK the order is based on the tabindex setting which may or may not be in the desired order.
    Yea, I am pretty sure thats true, but I assumed that was the order he was mentioning, maybe not though. Good point.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •