awohld has asked for the wisdom of the Perl Monks concerning the following question:

I have a data structure that I'm using in LWP::UserAgent and I want to extract it into one variable.

Here's my curent data structure as seen in the POST method of LWP::UserAgent:
my $response = $browser->post( $udr, [ "cellgroup" => "Chicago", "ucl" => "ALL", "table" => "AP", "gotcell" => "no", "col" => [ qw( KEY CPUTYPE INSTANCE SYSTEM ) ], "action" => "Get_Data" ],@netscape_headers );
I want to extract the structure below out of the POST method and store it in a variable:
[ "cellgroup" => "Chicago", "ucl" => "ALL", "table" => "AP", "gotcell" => "no", "col" => [ qw( KEY CPUTYPE INSTANCE SYSTEM ) ], "action" => "Get_Data" ]
So my post method looks like:

 my $response = $browser->post( $udr, $post_elements, @netscape_headers );

I tried assiging the data structure to a HASH and even as a string, but it didn't work. How do I do this?

Replies are listed 'Best First'.
Re: Making a Data Structure - Example
by japhy (Canon) on Sep 22, 2005 at 17:23 UTC
    It's not a hash (reference), it's an array reference. Note the square brackets (not curly braces).
    my $post_elements = [ ... ]; my $response = $browser->post($udr, $post_elements, @netscape_headers) +;
    The reason it's not a hash ref is to easily allow (without the need for references) multiple values for a single key.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: Making a Data Structure - Example
by planetscape (Chancellor) on Sep 22, 2005 at 21:20 UTC