...

View Full Version : Resolved forcing hashed params to output in a set order.



bazz
08-04-2009, 04:25 AM
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?



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

bazz
08-04-2009, 05:04 AM
Here's where I have got to.



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

bazz
08-04-2009, 05:45 AM
ah, got it. I had my loops in the wrong order.

bazz

KevinADC
08-04-2009, 06:39 PM
You can get the params as an array and loop over the array to preserve order. See the CGI documentation.

FishMonger
08-04-2009, 07:32 PM
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.

KevinADC
08-04-2009, 11:11 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum