Reputation: 6173
Please suggest how to assign query_string values to individual variable ?
my @values = split(/&/,$ENV{QUERY_STRING});
foreach my $i (@values) {
($fieldname, $data) = split(/=/, $i);
print "$fieldname = $data<br>\n";
}
I am getting values below. I am trying to assign to individual values like $org, $value,$source,$target.
key = MAIN
value = test
source = master
target = 123
Upvotes: 1
Views: 645
Reputation: 69244
Firstly, manual parsing of CGI parameters using code like that went out of fashion twenty years ago. You could be far better advised to use the param()
method from CGI.pm.
use CGI 'param';
foreach my $fieldname (param()) {
print "$fieldname = ", param($fieldname), "\n";
}
You could declare the variables directly.
use CGI 'param';
my $key = param('something');
my $value = param('something else');
# etc...
But perhaps it's better to store your parameters in a hash.
use CGI 'param';
my %param;
foreach (param()) {
$param{$_} = param($_);
}
And finally, it's 2015. Why are you still writing CGI programs?
Upvotes: 1