I'm trying to learn how to use CGI::Session. After extensive reading all day, googling, POD, etc., I'm at a loss as to why the following won't pass a variable to the next .pl that is called. (I want to use CGI::Session using a hidden field instead of a cookie). The first script runs fine, using HTML::Template, and prints the following at the bottom:

     my sid is: 004493c708b377edb6b73dbc5f6b9e61
     my f_name is: CGI::Session::File=HASH(0x1b303c)

The second script opens up Excel nicely but gives me an error message. NOTE: $sid is passed via a hidden field in a form, so I'm expecting it to move to the next script via &call_vars which moves all my other variables. Another note: if $sid didn't exist, use strict would complain.

However, it shows my $sid as being "1" and not the big long alphanumeric string I would have expected. So, since it doesn't appear that the $sid is being passed, I'm not really expecting f_name to show up... but I also wasn't expecting a param error either...

     my sid is: 1
     Software error: Can't call method "param" without a package
     or object reference at /local/.../SCRIPT2.pl line 12.

SCRIPT1 (which contains a button that calls SCRIPT2)

#!/usr/local/bin/perl5_8 use strict; use HTML::Template; use CGI::Session; use CGI ':standard'; my $CGI = CGI->new; &call_vars; #this calls via EXPORT all my variables like $sid $|=1; print $CGI->header; my $session = new CGI::Session("driver:File", undef, {Directory=>'/tmp +'}); $sid = $session->id(); $session->param('f_name', 'Sherzod'); #test variable #stuff that sets up template, generates @loop_data for template, etc. +snipped out $template->param(passdata => \@loop_data,); print $template->output(); print "<br>my sid is: $sid<br>"; print "<br>my f_name is: $session<br>";

SCRIPT2

#!/usr/local/bin/perl5_8 use strict; use HTML::Template; use CGI::Session; use CGI ':standard'; my $CGI = CGI->new; $|=1; print $CGI->header(-type => 'application/vnd.ms-excel'); print "<br>my sid is: $sid<br>"; my $f_name = $session->param('f_name'); #<=== Line 12 print "<br>my f_name is: $f_name<br>"; my $template = HTML::Template->new(filename => "SCRIPT2.tmp +l", associate => $CGI, loop_context_vars => 1, global_vars => 1, associate => $session );
Any clues for the clueless? TIA...

Lori


In reply to CGI::Session - trouble passing variables 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.