PDA

View Full Version : simple perl help


monkeyhead
04-27-03, 01:54 PM
http://monkeyheadstuff.com/temp/

the file form_processor.pl sorts fields when submitted (alphabetically)

I dont want it to sort them, just want them to remain in the order they are.

right now, in the HTML i have to do this... AAName, BBphone, CCaddress

any help appreciated.

thanks

cyberskye
04-29-03, 01:20 PM
Can't see your script...or the supporting html

monkeyhead
04-29-03, 05:01 PM
i zipped the file

cyberskye
05-01-03, 12:38 PM
Sorry - got a little distracted.

The sort statement is what puts them in order.

#Take all the fields that begin with a number, sort them by number and put them into #the sortedkeys array
foreach $key (sort(keys(%input))) {
if ($key =~ /user_email/) {
$user_email = "$input{$key}";
$user_email =~ s/^\d*\)\s*//;
$user_email =~ s/required-//;
}
unless ($key =~ /^\w+/) {
next;
}
push (@sortedkeys, "$key|$input{$key}");
}

monkeyhead
05-01-03, 12:52 PM
i dont want it to be sorted alphabetically or numerically... i want it to remain in the order on the page

cyberskye
05-01-03, 02:29 PM
Then either call the elements of the array implicitly (rather than foreach) or assign a variable to each field ($name, $email, etc) and work it that way. Kinda dirty and more code tho.

I'm not sure how it would sort the elements internally - without the sort, you may end up with unexpected results. Guess it can't hurt to try. Just remove SORT from the scrx and see what happens.

BTW the perl is about the best language for text/string manipulation. PHP may have more builtin functions that you'll find useful. PHP is pretty perl anyway, and can even run as your cgi engine if you want. Your ISP has to support it, tho.

Skye