I just wish it were even possible to roll my own at this stage! ;-)
I was jokingly referring to the 'googling' you did when you came up with all sorts of references to getting the $ENV variable and parsing it! Just don't do it please :)
As for CGI.pm, wouldn't CGI.pm's "stickyness" be the default behavior? I see where there's a pragma called "-nosticky". I can't seem to pass the variables to the second script, even though I successfully passed them to the first script (and I suspect it's because the variables were in a form and CGI.pm likes that). So, am I correct in my understanding that CGI.pm won't pass the form variables a second time because there's no form?
I am going to pass on comeenting here. Yes, as I recall, CGI.pm's default is sticky, but it is a LONG time since I used it that way.
I've been trying to play with CGI::Session, but I can't get it to work for me. I don't know if it's because I'm trying to save ALL my CGI form variables PLUS my TMPL_VAR variables... Is that even possible?
Sheesh! Why does everybody have trouble getting CGI::Session to work! It's easy. OK, here we go:
  1. Create you database table, make sure that you have the required two fields. e.g.
    SET FOREIGN_KEY_CHECKS=0; #---------------------------- # Table structure for sessions #---------------------------- CREATE TABLE `sessions` ( `id` varchar(32) NOT NULL default '', `a_session` text NOT NULL, UNIQUE KEY `id` (`id`) ) TYPE=MyISAM;
    and make sure that the 'a_session' is at least a BLOB size field.
  2. Set up the database and get a DBH object back.
    my $config = { DSN => 'DBI:mysql:session', MySQLunm => 'ipsofalco', MySQLpwd => 'ipsoquango', }; my $dbh = &createDBconnection( $config->{DSN}, $config->{MySQLunm}, $c +onfig->{MySQLpwd} ); # Get a CGI object, it will be filled if a form was #submitted and will have a cookie in teh header #if one had been set. my $q = new CGI; #Initialize the session, if their is a cookie in the #CGI object then the CGISESSID will be the value of an #existing session, otherwise it creates a new session my $session = new CGI::Session("driver:MySQL", $q, {Handle=>$dbh}); #$rdcookie is the value of the cookie that was already # in the header read=past tense in this case. my $rdcookie = $q->cookie("CGISESSID"); #$id is the session id (an MD5 hash) of the session. my $id = $session->id(); # Set cookie with new expire time my $cookie = $q->cookie(-name=>'CGISESSID', -value=>$session->id, -exp +ires=>'+1d');
  3. Now we can write to the session, read from it, clear it and expire things, like this in a crude shopping cart:
    sub addItemCart { my ($cgi, $session, $orderitem) = @_; my $orderitem = &getItemForCart($cgi, $session); # get current cart contents my $cart = $session->param("CART") || []; # add selected item push @{$cart}, $orderitem; # update the CART in the session $session->param( "CART", $cart ); $session->flush(); return displayCart($cgi, $session); }
    Does nothing more than get a hash of an item and adds it to the CART value(a list of hashes) which is saved in the session parameters.
  4. To clear the cart we clear the session value that was saved:
    sub clrCart { my ($cgi, $session) = @_; $session->clear(["CART"]); $session->flush(); return &displayCart($cgi, $session); }
    and in this case display the updated cart.
Save what you like int he session parameters. Save an entire HASH, darn it, save an array of hashes just like my silly little cart.

To see some more code - much more complete, have a look at jdtoronto's scratchpad The full working version is posted there.

jdtoronto


In reply to Re:^^ HTML::Template, CGI, pass template params to next script by jdtoronto
in thread HTML::Template, CGI, pass template params to next script by Lori713

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.