Category Archives: Perl

Perl script bad interpreter: Permission denied

Something went wrong on my perl code which was working earlier before I made an upgrade from debian etch to lenny.
Here are the errors :
debian:/home/jojo/Desktop/pepesfile/drupal/mysite# ./index.cgi
bash: ./index.cgi: /usr/bin/perl: bad interpreter: Permission denied

On the apache log :
[error] [client 192.168.1.2] (13)Permission denied: exec of '/home/jojo/Desktop/pepesfile/drupal/mysite/index.cgi' failed

I’ve been tracing the error on it. I simply commanded the perl index.cgi on it but its fine. I suspect that there are ^M character which the DOS/Windows based text editor is giving on the first few lines of code but its fine when I try to view via VIM[1].

And then I’ve tried to look at the way the folder mysite/drupal mounted on my /etc/fstab
Here is my entry:
UUID=38c8ec02-5ef7-49fd-8607-78e4b2fe78c7 /home/jojo/Desktop/pepesfile ext3 auto,rw,user 0 0

I did add the exec on the column auto,rw,user and remounted the partition but its still not working :(.

Finally i’ve replaced that auto,rw,user,exec to defaults.

Ahh.. that solved my problem.

According to the fstab documentation here[2], “defaults uses the default options that are rw, suid, dev, exec, auto, nouser, and async.” I just need to type the other options and remove the nouser, but I’m glad fstab has this default. 😀

[1] http://www.vim.org/
[2] http://www.tuxfiles.org/linuxhelp/fstab.html

Perl: Appending array in a hash element

My code :
push($parentmenu{$parentkey}{childlist},[$childmenu{$childid}{name},$childmenu{$childid}{link}]);

Gives me this error.

Type of arg 1 to push must be array (not hash element) at ./test.cgi line 34, near “])”
Execution of ./test.cgi aborted due to compilation errors.

And it was just resolved by adding the @ and enclose it with {} – see the code below. I need an explanation though, but I’ll have to find the explanation later, for the meantime the solution just worked for my task.

push(@{$parentmenu{$parentkey}{childlist}},[$childmenu{$childid}{name},$childmenu{$childid}{link}]);

Perl module in non-standard location

I’ve discovered a module in the CPAN in which i can use Ajax on my CGI script. This module is CGI::Ajax of www.perljax.us.
On my PC, the script I’ve created using the module runs without a problem but then when I upload and execute my script I have this issue:

Can’t locate CGI/Ajax.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/i686-linux /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i686-linux /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7/i686-linux /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl/5.6.2 /usr/lib/perl5/site_perl .) at ./test2.cgi line 15.
BEGIN failed–compilation aborted at ./test2.cgi line 15.

The CGI/Ajax.pm cant be located but then I have already installed that on my server. I realized then that ,since I’m only renting this server, the Perl module is not installed in the standard location.

To solved this, I need to include the code use lib. Lets say I’ve installed the module in /home/pepesmith/modules. ON the first line of my script, before calling the “use CGI::Ajax”, the code that must be inserted is :

use lib "/home/pepesmith/modules";

This means that the directory “/home/pepesmith/modules/” is included in the location of modules stated in @INC as stated here.

Fixing ^M error on text file

A few weeks back, with my new job, I’ve been plunging deeply into the Xen environment and Perl programming, but of course I believe I wont abandon being a Pythonista. After all, its my fav. language and I still have an unfinished project hosted in Sourceforge site.

When I try to run my python program, I’ve encountered this kind of error :

bash: ./pytodolist.py: /usr/bin/python^M: bad interpreter: Permission denied

Googling the solution for this one..I’ve found the answer which tells me to use a small perl code which is : perl -i.bak -pe ‘s/r//g’ *.py

Running again my program..It now works 🙂