As I mentioned, I've been working on this one problem for days. I've tried to use CGI::Cookie, copying the example directly from the CPAN page. I didn't care what data I wrote to the cookie file file, as long as I wrote something. Here's the script I used:
#!/usr/bin/perl #################################### use CGI qw/:standard/; use CGI::Cookie; sub write_cookie { my $c = new CGI::Cookie(-name => 'foo', -value => ['bar','baz'], -expires => '+3M' ); print header(-cookie=>[$c]); %cookies = fetch CGI::Cookie; $id = $cookies{'ID'}->value; %cookies = parse CGI::Cookie($ENV{COOKIE}); } 1;
This is what displays on the screen:

Set-Cookie: foo=bar&baz; path=/; expires=Wed, 29-Sep-2004 19:22:16 GMT Date: Thu, 01 Jul 2004 19:22:16 GMT Content-Type: text/html; charset=ISO-8859-1

The rest of the page is blank. Since this was even worse that what I was getting before, I returned to work with my former code.

I also tried CGI, using an example I was able to find:
#!/usr/bin/perl #################################### use CGI; $cgiobject=new CGI; $cgiobject->use_named_parameters; &get_state_variables; $cookie_data=&prepare_cookie; &set_cookie($cookie_data); return; sub get_state_variables() #retrieve from the CGI queries the keys and +value we want to store in the cookie { $b_first=$cgiobject->param("reg_custnamef"); $b_mid=$cgiobject->param("reg_custnamemi"); $b_last=$cgiobject->param("reg_custnamel"); } sub prepare_cookie() #packages the variables into one data string +for storage in cookie { $cookie_data="b_first=$b_first|". "b_mid=$b_mid|". "b_last=$b_last"; return $cookie_data; } sub set_cookie($cookie_data) #sets cookie on user's machine { $final_cookie=$cgiobject->cookie(-name=>'searchform', -value=>$cookie_data, -expires=>'+6M'); print $cgiobject->header(-cookie=>$final_cookie); } 1;
but I couldn't get it to run. I tried using SYSTEM and then EXEC, neither of which I've ever tried using before, but to no avail.


In reply to Re^2: Cookies write to screen, not to cookie file by TJD
in thread Cookies write to screen, not to cookie file by TJD

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.