Solved

Simple Perl syntax Q

Posted on 1998-10-26
1
169 Views
Last Modified: 2010-03-04
The following is part of a cgi program that outputs fields from a form:

foreach $key (sort(keys %in)) {
        print MAIL "  ",$key, "\t=", $in{$key}, "\n";
        }

I'd like to print out all the keys and values in unsorted order (ie, in the order in which they appear in the form).  How would I modify the code above to accomplish this?
0
Comment
Question by:alweiner
1 Comment
 
LVL 5

Accepted Solution

by:
b2pi earned 10 total points
ID: 1205719
foreach $key ( keys %in) {
    print MAIL " $key,\t=$in{$key}\n";
}

Will print out the keys in an unsorted order.  However, that will _NOT_ be the order that they appear in the form.  If you want to do that, set up an array with the keys in the proper order (i.e.

@keys = qw {name address1 city state zip whathaveyou};


foreach $key (@keys) {
    print MAIL "$key,\t=$in{$key}\n";
}


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl search and replace 6 165
PERL get the value for query 4 145
Get a Perl script to return content from a module 7 78
quoting a comma separated list 20 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now