Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Perl Question -- Combining arrays values into a string 1

Status
Not open for further replies.

lmcate2

IS-IT--Management
Aug 28, 2001
49
0
0
US
I have below my code that has the array and I want to be able to maka a variable to combine all string below.


STRING

&AgencyID=101000057&AgencyName=Test%20Ccra&AgentID=10014&AgentName=jeff%20kirk&AgentEmail=jkirk@me.com


CODE
#print "\n";
#print "<hr>\n";
foreach $namevalue (@namevaluepairs) {
( $name, $value ) = split ( /=/, $namevalue );
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\\dA-Fa-f])/ pack ("C",hex ($1))/eg;
$a = $a + 1;

$name{$a} = $name;
$responce{$a} = $value;
$Sam{$a}=$value;
$value{$a} = $value;

#print $a;print" = ";print $name; print " = ";
#print $responce{$a};print;
}

print '&AgencyID=',$responce{2};
print '&AgencyName=',$responce{3};
print '&AgentID=',$responce{5};
print '&AgentName=',$responce{4};
print '&AgentEmail=',$responce{6};

THANKS,

SAM
 
Code:
use CGI;
$q=new CGI;

print $q->param('AgencyID');
print $q->param('AgencyName');
print $q->param('AgentID');
print $q->param('AgentEmail');

HTH
--Paul

cigless ...
 
I am a newbie. Do I stick the code inside the for statemnt?????

Thanks,

Sam
 
No need for the for statement anymore.
Code:
#!/usr/bin/perl
use CGI;
$q=new CGI;
print $q->header;
print $q->param('AgencyID');
print $q->param('AgencyName');
print $q->param('AgentID');
print $q->param('AgentEmail');

That's it!
That will parse your query string, and print out the results

cigless ...
 
Can I Combined the values into a single string as:

"&AgencyId=40404&AgencyName=My Company&AgentName=Jeff Kirk"

Thanks a again,

Sam
 
Code:
print $env{'QUERY_STRING'};
should do that
HTH
--Paul

cigless ...
 
Nitpick - should be capitalised:
Code:
print $ENV{QUERY_STRING};

# alternatively, since we're using CGI;
print $q->query_string;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top