Solved

Simple Perl syntax Q

Posted on 1998-10-26
1
155 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

18 Experts available now in Live!

Get 1:1 Help Now