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

Hi guys

I posted the below code a few days ago for a different problem regarding Perl modules. I moved to a new host who has all the modules I need so that problem is gone.

The problem I am having now is bugging me because it doesn't make any sense to me. With fatalstobrowser in there I still get the 500 internal server error. I can't get my test print near the top to print anything at all. I checked my error logs on the server and nothing from this script ever gets flagged. Can someone see a syntax error in my code below?

The BEGIN statement was given to me from HostGator (my host) who has some new Perl module installer in Cpanel. Apparently if you use their mod installer there's that chunk of code that has to go near the top of the perl script.

I appreciate any help you can offer!
#!/usr/bin/perl BEGIN { my $base_module_dir = (-d '/home/askk/perl' ? '/home/askk/perl' : +( getpwuid($>) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; } use warnings; use strict; use CGI qw/:simple/; use CGI::Carp qw(fatalsToBrowser); print header; print "test"; use WWW::Mechanize; my $username = 'admin'; my $password = ''; my $url_to_sign_on = ''; my $post_new = ''; my $mech = WWW::Mechanize->new(); $mech->get($url_to_sign_on); $mech->submit_form( form_name =>'loginform', fields => { user_login => $username, user_pass => $password, } ); ###### # get html for page after sign on ###### my $page_source1 = $mech->content; if ($page_source1 =~ m/dashboard/i) { print "Sign on successful.<br><br>"; } else#!/usr/bin/perl BEGIN { my $base_module_dir = (-d '/home/askageek/perl' ? '/home/askk/perl +' : ( getpwuid($>) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; } use warnings; use strict; use CGI qw/:simple/; use CGI::Carp qw(fatalsToBrowser); print header; print "test"; use WWW::Mechanize; my $username = 'admin'; my $password = 'wfgs343R'; my $url_to_sign_on = 'http://www'; my $post_new = 'http://www.'; my $mech = WWW::Mechanize->new(); $mech->get($url_to_sign_on); $mech->submit_form( form_name =>'loginform', fields => { user_login => $username, user_pass => $password, } ); ###### # get html for page after sign on ###### my $page_source1 = $mech->content; if ($page_source1 =~ m/dashboard/i) { print "Sign on successful.<br><br>"; } else { print "sign on failed.<br><br>"; exit; } ##### # load page to post new post ##### $mech->get($post_new); if ($post_new =~ m/log out/i) { print "Post_new page loaded successfully.<br><br>"; } else { print "Post_new page failed to load.<br><br>"; exit; } ##### # Fill out the post form ##### $post_new =~ m#name\=\"_wponce\"\s+value=\"([a-z][0-9]){10}\"#i; print "found $1"; exit; $mech->submit_form( form_name =>'post', fields => { '_wpnonce' => '', '_wp_http_referer' => "/wp-admpin/post-new.php", parent_id => '0', user_ID => '1', action => 'editpost', originalaction => 'editpost', post_author => '1', post_type => 'post', original_post_status => 'auto-draft', referredby => 'http', '_wp_original_http_referer' => '_wp_original_http_referer', auto_draft => '1', post_ID => '', autosaveonce => '', 'meta-box-order-nonce' => '', } ); { print "sign on failed.<br><br>"; exit; } ##### # load page to post new post ##### $mech->get($post_new); if ($post_new =~ m/log out/i) { print "Post_new page loaded successfully.<br><br>"; } else { print "Post_new page failed to load.<br><br>"; exit; } ##### # Fill out the post form ##### $post_new =~ m#name\=\"_wponce\"\s+value=\"([a-z][0-9]){10}\"#i; print "found $1"; exit; $mech->submit_form( form_name =>'post', fields => { '_wpnonce' => '', '_wp_http_referer' => "/wp-admin/post-new.php", parent_id => '0', user_ID => '1', action => 'editpost', originalaction => 'editpost', post_author => '1', post_type => 'post', original_post_status => 'auto-draft', referredby => 'http', '_wp_original_http_referer' => '_wp_original_http_referer', auto_draft => '1', post_ID => '', autosaveonce => '', 'meta-box-order-nonce' => '', } );

Readmore tags added by GrandFather

Replies are listed 'Best First'.
Re: internal server error- cant find error
by Corion (Patriarch) on Mar 16, 2011 at 16:08 UTC

    Look in your webserver error log - the full error is there.

      I did look in the server logs but nothing from this script gets mentioned. That is what is bugging me about this.

        If your webserver error log does not mention anything about your access to the web page, then either your browser is caching the wrong result or you are looking at the wrong log file, or are accessing the wrong webserver.

Re: internal server error- cant find error
by marto (Cardinal) on Mar 16, 2011 at 16:13 UTC
Re: internal server error- cant find error
by Anonymous Monk on Mar 16, 2011 at 16:56 UTC
Re: internal server error- cant find error
by Anonymous Monk on Mar 16, 2011 at 16:33 UTC
    Sorry everyone, I posted messed up code (that's what happens when I try to manage my site and code through my smartphone!

    The code below is what I'm actually using.
    !/usr/bin/perl BEGIN { my $base_module_dir = (-d '/home/askk/perl' ? '/home/askk/perl' : +( getpwuid($>) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; } use warnings; use strict; use CGI qw/:simple/; use CGI::Carp qw(fatalsToBrowser); print header; print "test"; use WWW::Mechanize; my $username = 'admin'; my $password = ''; my $url_to_sign_on = 'http://www'; my $post_new = 'http://www.'; my $mech = WWW::Mechanize->new(); $mech->get($url_to_sign_on); $mech->submit_form( form_name =>'loginform', fields => { user_login => $username, user_pass => $password, } ); ###### # get html for page after sign on ###### my $page_source1 = $mech->content; if ($page_source1 =~ m/dashboard/i) { print "Sign on successful.<br><br>"; } else { print "sign on failed.<br><br>"; exit; } ##### # load page to post new post ##### $mech->get($post_new); if ($post_new =~ m/log out/i) { print "Post_new page loaded successfully.<br><br>"; } else { print "Post_new page failed to load.<br><br>"; exit; } ##### # Fill out the post form ##### $post_new =~ m#name\=\"_wponce\"\s+value=\"([a-z][0-9]){10}\"#i; print "found $1"; exit; $mech->submit_form( form_name =>'post', fields => { '_wpnonce' => '', '_wp_http_referer' => "/wp-admpin/post-new.php", parent_id => '0', user_ID => '1', action => 'editpost', originalaction => 'editpost', post_author => '1', post_type => 'post', original_post_status => 'auto-draft', referredby => 'http', '_wp_original_http_referer' => '_wp_original_http_referer', auto_draft => '1', post_ID => '', autosaveonce => '', 'meta-box-order-nonce' => '', } ); { print "sign on failed.<br><br>"; exit; } ##### # load page to post new post ##### $mech->get($post_new); if ($post_new =~ m/log out/i) { print "Post_new page loaded successfully.<br><br>"; } else { print "Post_new page failed to load.<br><br>"; exit; } ##### # Fill out the post form ##### $post_new =~ m#name\=\"_wponce\"\s+value=\"([a-z][0-9]){10}\"#i; print "found $1"; exit; $mech->submit_form( form_name =>'post', fields => { '_wpnonce' => '', '_wp_http_referer' => "/wp-admin/post-new.php", parent_id => '0', user_ID => '1', action => 'editpost', originalaction => 'editpost', post_author => '1', post_type => 'post', original_post_status => 'auto-draft', referredby => 'http', '_wp_original_http_referer' => '_wp_original_http_referer', auto_draft => '1', post_ID => '', autosaveonce => '', 'meta-box-order-nonce' => '', } );

      If that is really your code, then the first line is not what it should be. Again, look in your webserver error log. Also, it might help to compare the first line of your now posted code with the first line of other scripts that work and adjust it correspondingly.