Passing Post Params & Object Reference ?

S

still me

I am using LWP to do a POST. I need some help automating the passing
of parameters and getting the object reference to work.

Here's the (hard coded) version that works fine;
my $response = $browser->post( $url,['test1'=>'001', 'test2' => 'it
works']););

What I'd like to do is to set up an array (or hash) with the parameter
names and values so that I can change the parameters to be passed as
simply by altering the hash names/values. Then I'd just generate the
passed parameter string for as many values as are in the array.

Here's a hardcoded sample (no array for simplicity) that I tried as a
test just to figure out how to get the parameters passed:

my $param1 = "'test1'=>'001',";
my $param2 = "'test2'=>'002'";
my $response = $browser->post( $url,[$param1, $param2]);

But, it didn't pass the parameters. I assume that's because I
destroyed the object reference by doing what I did, but I don't
understand Perl objects and variable translation enough to know how to
construct a working object reference.

Thanks for any help,
 
G

Gunnar Hjalmarsson

still said:
I am using LWP to do a POST. I need some help automating the passing
of parameters and getting the object reference to work.

Here's the (hard coded) version that works fine;
my $response = $browser->post( $url,['test1'=>'001', 'test2' => 'it
works']););

What I'd like to do is to set up an array (or hash) with the parameter
names and values so that I can change the parameters to be passed as
simply by altering the hash names/values. Then I'd just generate the
passed parameter string for as many values as are in the array.

Here's a hardcoded sample (no array for simplicity) that I tried as a
test just to figure out how to get the parameters passed:

my $param1 = "'test1'=>'001',";
my $param2 = "'test2'=>'002'";
my $response = $browser->post( $url,[$param1, $param2]);

Try this:

my %params = ( test1 => '001', test2 => '002' );
my $response = $browser->post( $url, [ %params ] );
 
S

still me

Here's a hardcoded sample (no array for simplicity) that I tried as a
test just to figure out how to get the parameters passed:

my $param1 = "'test1'=>'001',";
my $param2 = "'test2'=>'002'";
my $response = $browser->post( $url,[$param1, $param2]);

Try this:

my %params = ( test1 => '001', test2 => '002' );
my $response = $browser->post( $url, [ %params ] );

Thanks, that got me going in the right direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top