#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use strict; use CGI; use Data::Dumper; my $cgi = CGI->new(); my %cgiParam = $cgi->Vars; # Store CGI params into a hash my @cgiParamKeys = keys %cgiParam; # Store the %cgiParam keys into an array my @cityKeys; my @distanceKeys; foreach( @cgiParamKeys ) { if( /city/ ) { #If a hidden city field found store it in an array; push @cityKeys, $_; #Store the field in an array @cityKeys = sort @cityKeys; #Sort the array } if( /distance/ ) { #If a hidden distance field found, store it in an array push @distanceKeys, $_; #Store it in the array @distanceKeys = sort @distanceKeys; #Sort the array } } my $numLocations = @cityKeys; #Store the last city and distance submited as the last City and distnace element in the hash $cgiParam{"city$numLocations"} = $cgiParam{'postCity'}; $cgiParam{"distance$numLocations"} = $cgiParam{'postDistance'}; ### #Store new keys into array used for printing hidden keys push @cityKeys, "city$numLocations"; push @distanceKeys, "distance$numLocations"; ### my @hiddenKeys = qq(@cityKeys @distanceKeys); print $cgi->header; print Dumper %cgiParam; print "

"; print Dumper @hiddenKeys; print $cgi->start_form(-action=>'help.pl'); foreach( @hiddenKeys ) { if(/city/) { print $cgi->hidden("$_", "$cgiParam{$_}"); } if(/distance/) { print $cgi->hidden("$_", "$cgiParam{$_}"); } } print <    Distance: 
EOF print $cgi->submit('Go'); print $cgi->end_form;