in reply to Re: Help choosing the most efficient, dependable condition(al)
in thread Help choosing the most efficient, dependable condition(al)

Greetings daxim.

FWIW, there's an issue with your example above:

# your version print "Content-Type: application/xhtml+xml; charset=UTF-8\n"; } else { print "Content-Type: text/html; charset=UTF-8\n"; # MY version print "Content-Type: application/xhtml+xml; charset=UTF-8\n\n"; } else { print "Content-Type: text/html; charset=UTF-8\n\n";
For the record; it takes 2 newlines (\n\n).
:)

--Chris

#!/usr/bin/perl -Tw
use Perl::Always or die;
my $perl_version = (5.12.5);
print $perl_version;

Replies are listed 'Best First'.
Re^3: Help choosing the most efficient, dependable condition(al)
by daxim (Curate) on Nov 13, 2013 at 23:44 UTC
    Not if send another header, namely "Vary". See the code update in Re: Help choosing the most efficient, dependable condition(al)

    There's a lot to be gained by using a Web framework (you are familiar with CGI.pm, try Plack::Request/Plack::Response), where one doesn't have to care about newlines at all - the software handles the correct formatting for me. Short example: plackup -MPlack::Request -e'sub { my $req = Plack::Request->new(shift); return $req->new_response(200, [Content_Type => "text/html", Vary => "Accept"], [])->finalize }'

    Doing the formatting manually and needing to get it correct is the real overhead. The work time of a programmer is expensive.

      In my humble defense daxim.

      When I use your revised edition, Perl throws:

      malformed header from script. Bad header=<?xml version="1.0" encoding= +": vary-test.cgi
      But, if I simply add an additional \n to each of the content-type lines:
      print "Content-Type: application/xhtml+xml; charset=UTF-8\n\n"; } else { print "Content-Type: text/html; charset=UTF-8\n\n";
      no errors thrown.

      I've been meaning to have a look at plackup. I've seen alot of people using it.

      Thanks for mentioning it.

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;