Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Checking if a header has been printed

by Spidy (Chaplain)
on Nov 26, 2007 at 15:29 UTC ( #653005=perlquestion: print w/ replies, xml ) Need Help??
Spidy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, all.

I am currently working on a Perl project that uses a few "quick cookies" - that is, cookies that I only need for a minute or two, and can then discard.

Thus far, I have been printing my cookies using the CGI->header() command, but in cases where I have printed a cookie, I need to be sure not to print another header - or it appears at the top of my page.

Does anyone know of a way that I could check to see if a header has been printed, to make sure that I don't "overlap" my headers?

Thanks,

Spidy

Comment on Checking if a header has been printed
Download Code
Re: Checking if a header has been printed
by ikegami (Pope) on Nov 26, 2007 at 15:38 UTC

    CGI has a flag that causes subsequent calls to header to be silently ignored.

    $CGI::HEADERS_ONCE = 1;

    However, it's only documented in the source, not in the pod. The alternative would be to make your own flag.

    if ($cgi_header_already_printed++) { warn("Attempting to send second CGI while trying to ...\n"); } else { print CGI->header(); }
Re: Checking if a header has been printed
by Cubes (Pilgrim) on Nov 26, 2007 at 16:18 UTC
    A whole 'nother approach would be to not print anything at all in the guts of your program, instead stashing away all of your header (and possibly content) data until the very end, where everything gets printed at once.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://653005]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2014-09-16 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (47 votes), past polls