in reply to Header Visible In CGI output after cookie header is sent

If you print headers in several places (eg, depending on action to take), you might want to set up a couple of subs to keep your vars nice and local, eg:
#!/usr/bin/perl -w use strict; use CGI; my $q = CGI->new(); # create cookie my $cookie1 = $q->cookie(-name=>'sessionID', -value=>'xyzzy', -expires=>'+1h', -path=>'/'); # set cookie set_cookie($cookie1); # create another cookie my $cookie2 = $q->cookie(-name=>'another_one', -value=>'abbaaba', -expires=>'+1h', -path=>'/'); # set other cookie set_cookie($cookie2); # or, set both cookies at the same time set_cookie($cookie1,$cookie2); print cookie_header(), $q->start_html, $q->p('hello'), $q->end_html; exit(0); # this is the localized 'cookie jar' :) { my @cookies = (); sub set_cookie { push @cookies, @_; } sub cookie_header { $q->header(-cookie=>[@cookies]); } }
And if there's no cookies to be set, no problem as far as the script is concerned - so just replace $q->header with cookie_header() throughout and you can stop worrying.

.02

cLive ;-)

--
seek(JOB,$$LA,0);