You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by perl <pe...@wcn.co.uk> on 2000/08/21 11:21:36 UTC

Passing a hash to a cgi outside a form?

Hi there!

Sorry for this question which might sound easy to you, but, does anyone know :
How can a CGI pass and receive a hash without a form?

Please have a look at the following simple scripts :

This is test.cgi
-----------------------
#!/usr/bin/perl
use CGI;

$list->{'value1'} = 'apple';
$list->{'value2'} = 'fruit';

print "Location: test2.cgi?list=$list \n\n";
----------------------

This is test2.cgi
----------------------
#!/usr/bin/perl

use CGI qw (:standard);

print header;

$list = param('list');

foreach (keys %{$list})
{
        print "KEY IN LIST = ",$_,br;
}

----------------------

Thank you for your help !

Re: Passing a hash to a cgi outside a form?

Posted by Ruben I Safir <ru...@sruben.dental.nyu.edu>.
Passing a Hash is a CGI proble (and done like all hash passing). 
Mod_perl is not CGI.

Please - if you can. try to send messages as text only without an
attachment.

Ruben

> perl wrote:
> 
> Hi there!
> 
> Sorry for this question which might sound easy to you, but, does
> anyone know :
> How can a CGI pass and receive a hash without a form?
> 
> Please have a look at the following simple scripts :
> 
> This is test.cgi
> -----------------------
> #!/usr/bin/perl
> use CGI;
> 
> $list->{'value1'} = 'apple';
> $list->{'value2'} = 'fruit';
> 
> print "Location: test2.cgi?list=$list \n\n";
> ----------------------
> 
> This is test2.cgi
> ----------------------
> #!/usr/bin/perl
> 
> use CGI qw (:standard);
> 
> print header;
> 
> $list = param('list');
> 
> foreach (keys %{$list})
> {
>         print "KEY IN LIST = ",$_,br;
> }
> ----------------------
> 
> Thank you for your help !

-- 
Ruben I Safir

ruben@sruben.dental.nyu.edu
ruben@wynn.noSppam.com

Perl Notes:
http://www.wynn.com/jewish/perl_course

http://www.brooklynonline.com
Manager of Intranet Development NYU College of Dentistry
Resume:  http://www.wynn.com/jewish/resume.html

Re: Passing a hash to a cgi outside a form?

Posted by Dana Powers <da...@quicknet.net>.
You might also try Data::Dumper to create eval-able expressions -> hashes,
arrays, and other complex objects.

Dana

Re: Passing a hash to a cgi outside a form?

Posted by Alex Menendez <am...@hotbacon.com>.
you can't do this, dude. test.cgi dies and so do all it's pointers to
structures in memory.

try looking at Apache::Registry or mod_perl with the Apache::Filter
mod.

Or if you want to keep these things as cgi's look at LWP which lets you
make http requests from within perl programs. 

However, I would probably just make some subroutines that both cgis could
use via require or use. the memory structures still are destroyed when the
cgi dies.

 It really depends if your intent is to reuse code or pass a
structure that is already in memory. if it is the former, look at LWP or
the subroutine example. if it is the former, checkout the mod_perl and
Filter stuff.

hope this helps,
-amen 

On Mon, 21 Aug 2000, perl wrote:

> Hi there!
> 
> Sorry for this question which might sound easy to you, but, does anyone know :
> How can a CGI pass and receive a hash without a form?
> 
> Please have a look at the following simple scripts :
> 
> This is test.cgi
> -----------------------
> #!/usr/bin/perl
> use CGI;
> 
> $list->{'value1'} = 'apple';
> $list->{'value2'} = 'fruit';
> 
> print "Location: test2.cgi?list=$list \n\n";
> ----------------------
> 
> This is test2.cgi
> ----------------------
> #!/usr/bin/perl
> 
> use CGI qw (:standard);
> 
> print header;
> 
> $list = param('list');
> 
> foreach (keys %{$list})
> {
>         print "KEY IN LIST = ",$_,br;
> }
> 
> ----------------------
> 
> Thank you for your help !
>