perlheaderperl-modulewww-mechanize

malformed header from script. Bad header=<!DOCTYPE html>


I am receiving the following server error on a perl script:

malformed header from script. Bad header=: youtube_perl.pl,

Here is my source code:

#!"C:\XAMPP\perl\bin\perl.exe" -T

use strict;
use warnings;

use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use WWW::Mechanize;

my $q = CGI->new;

my $url = 'http://www.youtube.com';

my $mechanize = WWW::Mechanize->new(autocheck => 1);

$mechanize->get($url);

my $page = $mechanize->content();

print $page;

Solution

  • Figured it out. Had to add the following before I attempted to print the page:

    print "Content-type: text/html\n\n";
    

    I guess perl can not print html pages without defining the header first.