in reply to Checking a header is printed already?

You could use a global variable (accessible from every place where you're potentially outputting the header) to keep track of whether it's already been printed:

unless ($header_printed) { $header_printed = print $IN->header; }

Replies are listed 'Best First'.
Re^2: Checking a header is printed already?
by Anonymous Monk on Oct 06, 2009 at 11:52 UTC
    Oh , CGI,
    #### Method: header # Return a Content-Type: style header # #### 'header' => <<'END_OF_FUNC', sub header { my($self,@p) = self_or_default(@_); my(@header); return "" if $self->{'.header_printed'}++ and $HEADERS_ONCE;
    # Change this to 1 to suppress redundant HTTP headers $HEADERS_ONCE = 0;
    $HEADERS_ONCE++, next if /^[:-]unique_headers$/;
    use CGI qw( -unique_headers );
      Hmmm, utilising & referencing a modules' implementation details ... definitely a bad idea!!

      A user level that continues to overstate my experience :-))
        Hmmm, utilising & referencing a modules' implementation details ... definitely a bad idea!!

        How? You think there is another choice with CGI.pm? CGI::Simple OTOH actually documents -unique_header

      Hi,

      Thanks for the replies guys.

      From looking at that header() bit in CGI.pm, it looks like CGI.pm already does the checking for me? (maybe that would explain why I'm not seing "Content-Type: text/html" printed several times, where the header is called :)

      Thanks!

      Andy
        It is an option, you enable it with
        use CGI qw( -unique_headers );