Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Perl/CGI - passing AoH from one page to another

by sara2005 (Scribe)
on Nov 14, 2005 at 14:28 UTC ( [id://508320] : perlquestion . print w/replies, xml ) Need Help??

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

I have an Array of Hashes which I would like to pass from one web-page to another using CGI. Please suggest any ideas. Here is the structure i have printed using Data::Dumper
[ { 'PageNum'=>1, 'VarName' => 'name1', 'Value' => ' value1', 'Min' => ' min1', 'Max' => ' max1', 'Mod' => ' ' }, { 'PageNum'=>1, 'VarName' => 'name2', 'Value' => ' value2', 'Min' => ' min2', 'Max' => ' ', 'Mod' => ' ' }, etc.. etc.. { 'PageNum'=>2, 'VarName' => 'nam1', 'Value' => ' val1', 'Min' => ' ', 'Max' => ' ', 'Mod' => ' ' }, { 'PageNum'=>2, 'VarName' => 'nam2', 'Value' => ' val2', 'Min' => ' mn2', 'Max' => ' ', 'Mod' => ' ' }, etc..etc.. ]

Replies are listed 'Best First'.
Re: Perl/CGI - passing AoH from one page to another
by dorward (Curate) on Nov 14, 2005 at 14:35 UTC

    The easiest solution would probably involve storing it in a session variable, probably with CGI::Session or Apache::Session.

    Another option would be to serialize the data and pass it via the query string (which could well run into problems with the amount of data you have) or by storing it in an input and submitting it as POST data (if the action you are performing is suitable for a POST request).

Re: Perl/CGI - passing AoH from one page to another
by Moron (Curate) on Nov 14, 2005 at 16:59 UTC
    The normal way is to maintain session information in a relational database, but it seems that in your case you really want a Storable. The missing link with using the ::Session modules (already mentioned) is that they are a bit DBI orientated. However, that can still be resolved by creating a DBI interface to your storable to be used by your session objects.

    Update: I just ran into Apache::Session::Serialize::Storable which seems to have addressed all this (and transparently to the programmer).


    Free your mind

Re: Perl/CGI - passing AoH from one page to another
by ickyb0d (Monk) on Nov 14, 2005 at 16:05 UTC
    Could store it in javascript object. Set a hidden field to the 'string' value of javascript object upon submission. Then use the JSON module to interpret it in the CGI script. might give you some more insight into this as well.

      Converting to JSON would be one technique you could use for serializing the data. I wouldn't have thought you would need to pass it though JavaScript though, that would put extra processing requirements on the client and break if JS was, for some reason, not available. You should be able to simply drop the JSON string into the hidden input (after encoding any characters that need to be represented by entities with HTML::Entities).

      See my previous comments about GET length and the suitability of POST though.