Stefany has asked for the wisdom of the Perl Monks concerning the following question:

I humbly seek the wisdom of the Perl Monks!

I am training my web-scraping skills with Perl!

So I have this code:

#!C:\xampp\perl\bin\perl.exe use utf8; use Text::Unidecode; use Web::Query; use DBI; print "content-type: text/html \n\n"; wq('http://example.com') ->find('h1') ->each(sub { my $i = shift; $i++; push(@array, $_->text . "\n"); return @array; }); foreach ( @array ) { print $_ . "\n"; }
When I run in it in the CMD ( I have Win 7 ) it works perfectly, but when I run it in the browser, I get error 500

Server error! The server encountered an internal error and was unable to complete yo +ur request. Error message: End of script output before headers: test.pl If you think this is a server error, please contact the webmaster. Error 500 localhost Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3


Please tell me why is that : / I am out of ideas. Many thanks!

Replies are listed 'Best First'.
Re: Use of a module(s) fetches error 500!
by Corion (Patriarch) on Mar 11, 2015 at 12:32 UTC

    Have you looked into what the web server error log says?

    There are many things why this might go wrong and most likely the error log contains the exact cause.

Re: Use of a module(s) fetches error 500!
by locked_user sundialsvc4 (Abbot) on Mar 11, 2015 at 12:40 UTC

    Pay particular attention to the library search-path, which normally is specified by a PERL5LIB environment-variable that you probably “set, long ago, in .bash_profile or someplace, and then promptly forgot about.”   A script that is designed to work in a browser often uses the use lib declaration to explicitly set the module-path that is to be used.   Or, environment-variables can be set up in Apache (or nginix), such that they will exist and have the proper values when the Perl script runs.

    This is actually a very common “head-banger problem” that pops up when you’re doing any sort of CGI (and, in an entirely different way, mod_yourlanguage) work.   Your script is now running in a completely different environment, and it’s probably running as nobody.

    The error_log for this site (virtual-host ...) will contain the complete message that was produced by Perl (or whatever-it-is).   So, that’s the place to begin.