in reply to Re: Re: Re: Re: use CGI
in thread making a hash from cgi parameters

Here's an easy way to deal with that.

my %post_data = map { $_ => param( $_ ) } param; my %url_data = map { $_ => url_param( $_) } url_param; my %data = merge( \%post_data, \%url_data ); sub merge { my %merged; for (@_) { while (my ($key, $value) = each %$_) { push @{$merged{$key}}, $value; } } %merged; }

%data will then contain all key value pairs. Note, this is not the best way to do this, but it's fairly easy to understand (though you'll want to read about map and references to grok all of it). Further, all values will be list references with this method, so accessing a single 'color' parameter would be $data{'color'}->[0]. The other option is to leave the two hashes separate and use them as necessary, but then you again have two data structures for one type of data. Yuck.

Oh, and the &merge is from MeowChow :)

As a side note: you shouldn't be mixing GET and POST. They have different uses. GET is for getting info and POST is for posting info. GET requests are often cached and POST requests shouldn't be. Mixing these methods could have undesireable side-effects.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.