The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Perl's "do" command -- reasons for not working?

Discussion in 'General Discussion' started by rogergraves, Dec 30, 2004.

  1. rogergraves

    rogergraves Member

    Joined:
    Dec 29, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I'm new at cPanel and am running it on Red Hat Enterprise 3 with Perl 5.8.4. I like to organize common subroutines that I use across more than one script into files that I import using perl's "do" command, e.g.:

    do "common_subroutines.pm"; # (is in same directory)

    For some reason it completely bombs out with a 500 error "premature end of script headers" which I interpret to mean that it isn't being allowed to read it. The subroutine file has chmod 666 and I've even tried 777 and to no avail. I've also tried doing an absolute path, i.e.

    do "/home/username/public_html/cgi-bin/common_subroutines.pm";

    Obviously I can roll these into the module library and do the "use" command but some of these I don't use for more than a few scripts so that seems like a lot of hassle, especially since I fiddle with them all the time. Anyone have any ideas?

    Thanks,
    ~Roger
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    That's odd. I use perl do all the time in our scripts and have no problems on cPanel servers. Are you ending your pm files with the following on its own as the last line of the module:

    1;

    If that's not the problem you can try the following:

    1. From the shell prompt:

    perl -c myscript.cgi

    Will check your script syntax. Or, add the following to the top of the calling script (after the first shebang line) as it's a CGI script:

    use CGI::Carp qw(fatalsToBrowser);

    Which may give you more information in your browser when you get the 500 error.
     
  3. rogergraves

    rogergraves Member

    Joined:
    Dec 29, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Yeah, it doesn't make any sense. It runs fine on a bunch of other servers. Here's the code:

    Code:
    #=== M A I N    P R O G R A M ===========================================
    # Name: test.pl
    use strict;
    do "subroutines.pm";
    {
    	print "<HTML><BODY>Current time: " . getNow() . "</BODY></HTML>";
    }
    #=== M A I N    P R O G R A M    E N D =====================================
    
    
    #=== S U B R O U T I N E S =============================================
    # Name: subroutines.pm
    sub getNow {
    	my ($minute, $hour, $day, $month, $year) = (localtime)[1,2,3,4,5];
    	my $timetype = 'a.m.';
    	$timetype = 'p.m.' if $hour > 12;
    	$hour = $hour - 12 if $hour > 12;
    	$year += 1900;
    	$month += 1;
    	$day = '0' . $day if $day < 10;
    	$month = '0' . $month if $month < 10;
    	return "$hour:$minute $timetype $month/$day/$year";
    
    }
    1;
    #=== S U B R O U T I N E S    E N D =======================================
    
    I did try your suggestion of use CGI::Carp qw(fatalsToBrowser); but didn't give any additional information. Also both files compile no problem on the server (perl -c test.pl & perl -c subroutines.pm both return "syntax OK").
     
  4. rogergraves

    rogergraves Member

    Joined:
    Dec 29, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Doh!

    As soon as I posted the last reply I saw the problem. It wasn't the "do" command at all -- I had forgotten to put in the print "Content-type: text/html\n\n" since I wasn't using the CGI module. Thanks for the response chirpy and sorry for the false alarm. :rolleyes:
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    It's always staring you in the face in the end :) well done for spotting it.
     
Loading...

Share This Page