1

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
1
  • No issues. I found the solution. I pushed the values and and assigned to variable from array like below. @urlvalues, $data; } my $key = $urlvalues[0]; my $value = $urlvalues[1]; Commented Dec 14, 2015 at 11:04

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.