in reply to Problem running cgi script (Exec format error)

It looks like you may be taking the advice given in Re: Trouble with Perl CGI script a bit too literally. The lines there should be at the top of the script, but still underneath the line
#!/usr/local/bin/perl
This is because when you are executing a script as an executable it needs to start with the shebang line. However, I'm not so sure this will actually help you. I think you might want to reread the whole thread in your earlier question Trouble with Perl CGI script, particularly the discussion started by ChrisR.

Replies are listed 'Best First'.
Re^2: Problem running cgi script (Exec format error)
by chakkaln (Sexton) on Jul 29, 2005 at 03:19 UTC
    Thanks for the message. To start with I had tried with the shebang line followed by setting the path for library. But that retuned the error message that it cant find the GD module Fri Jul 29 12:46:02 2005 error client 127.0.0.1 Premature end of script headers: /home/nagesh/apache/cgi-bin/simpleImage.cgi Can't locate GD.pm in @INC (@INC contains: /usr/local/lib/perl5/5.8.6/i686-linux /usr/local/lib/perl5/5.8.6 /usr/local/lib/perl5/site_perl/5.8.6/i686-linux /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl .) at /home/nagesh/apache/cgi-bin/simpleImage.cgi line 8. BEGIN failed--compilation aborted at /home/nagesh/apache/cgi-bin/simpleImage.cgi line 8. Fri Jul 29 13:16:05 2005 error client 127.0.0.1 Premature end of script headers: /home/nagesh/apache/cgi-bin/simpleImage.cgi This was the reason I moved it to top line before shebang which dint give me the error message about the missing GD module. Thanks Nagesh
Re^2: Problem running cgi script (Exec format error)
by chakkaln (Sexton) on Jul 29, 2005 at 03:25 UTC
    Hi This is the the output of @INC from the browser /usr/local/lib/perl5/5.8.6/i686-linux /usr/local/lib/perl5/5.8.6 /usr/local/lib/perl5/site_perl/5.8.6/i686-linux /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl from the command line /home/nagesh/progs/lib/perl5//i686-linux /home/nagesh/progs/lib/perl5/ /usr/local/lib/perl5/5.8.6/i686-linux /usr/local/lib/perl5/5.8.6 /usr/local/lib/perl5/site_perl/5.8.6/i686-linux /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl The first two line from the command line out put are missing from the browser output How do I make the change? Thanks
      Well, maybe GD is installed in your home directory. In that case, I guess the simplest way would be to add the following at the beginning of your script (though still underneath the #! line):
      BEGIN { unshift @INC, '/home/nagesh/progs/lib/perl5/i686-linux', '/home/nagesh/progs/lib/perl5/'; }
      Putting it in a BEGIN is important because otherwise it won't have any affect when you say use GD a few lines later. See perlmod for all the details. But, this makes it especially important that the files in your home directory are readable by Perl, which is not running under your user but rather as the Apache account.
        Hi There, Thanks a lot for the help. The code finally works!!!! It was a great relief for me to see it working. Thanks for bearing with me. Cheers Nagesh