I'm not the most experienced with HTTP/CGI so someone correct me if I'm wrong (please!), but I'm thinking that this could be due to the timing here if the second snippet you included is in the same script as the first.
My logic is thus: setting a cookie is just including a header line with the desired contents of the cookie to the client. However, since the clients' cookies are sent upon request of a page (and before the http header returned by the server), it wouldn't be available upon the first execution of the script. That would explain why you have to try twice before successfully fetching it - once to set the cookie, and once again to retrieve it.
If this is truly the problem, there's really no recourse to having to call the thing twice, whether it's with the cookie-setting and the cookie-fetching being in the same script or different scripts. Or if you can find a way to travel faster than light you can bypass the causality constraints.
If you manage to do the latter with Perl, make sure you post it to CUFP...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.