The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl5

# Very much like the reference.pl example, except for the fact 
# that we're calling the parse_form_data in a different context;
# the method returns a hash, so we don't need to dereference.

use CGI::Lite;

$cgi  = new CGI::Lite;
%data = $cgi->parse_form_data;

print "Content-type: text/plain", "\n\n";

while (($key, $value) = each %data) {

    # Let's check to see if a value is a reference to an array,
    # which indicates multiple values for the field.

    if (ref $value) {
	@all_values = $cgi->get_multiple_values ($value);

	print "$key = @all_values\n";
    } else {
	print "$key = $value\n";
    }
}

print "\nHere are the same key/value pairs in order:\n";

foreach $key ($cgi->get_ordered_keys) {
    $value = $data{$key};

    if (ref $value) {
	@all_values = $cgi->get_multiple_values ($value);

	print "$key = @all_values\n";
    } else {
	print "$key = $value\n";
    }
}

exit (0);