perl scripts and directories

karavite

Registered
Hope this isn't too much a dumb newby question, but:

How do you tell a perl script to look in the user's home directory? "~/" does not seem to work.
 
In the Apache httpd.conf file change the line that reads:

AllowOverride None

to

AllowOverride Options

Then, in the directory where you want to allow CGI execution create a file named .htaccess that contains this line:

Options +ExecCGI

You'll also need to make sure there's a line in httpd.conf like this:

AddHandler cgi-script .cgi .pl

You can instead set Options for directories in the httpd.conf file but the .htaccess method is more modular. The details of all this are posted here.
 
slur = God!

Thanks and sorry - I should have been more clear. I was wondering how you would do this for just a plain old perl script that runs "locally" - you know, from the users ~/bin directory. I'm learning perl and for my own learning purposes I am writing a script to edit my .xinitrc file and switch window managers used by XDarwin. I doubt anyone else would want to use this (it's probably just as quick to edit the file manually!), but I was wondering how I could make it more generic - run for anyone who put it in their ~/bin directory.

For example - this works:
open (XINIT, '/Users/dean/.xinitrctest') || die ("Could not open ~/.xinitrctest");

but this:
open (XINIT, '~/.xinitrctest') || die ("Could not open ~/.xinitrctest");

causes this:

[localhost:~] dean% wmpik.pl
Could not open ~/.xinitrctest at /Users/dean/bin/wmpik.pl line 33.
[localhost:~] dean%

I'll save your post for when I get into the whole cgi thing (soon I hope), but for now I am just having fun manipulating text on my own files. Thanks!
 
You're looking for the %ENV variable:

open (XINIT, "$ENV{ 'HOME' }/.xinitrctest") || die ("Could not open $ENV{ 'HOME' }/.xinitrctest");
 
Thanks - this is it - the only Perl book I have uses Windows examples for dealing with directories! I need to go shopping again.
 
Wow, I can't believe I misread the question so badly. Damn.

Yeah, using "$ENV{HOME}/.myscript" does the trick alright. I also like calling scripts in perl like so and capturing the standard output:

@output = `$ENV{HOME}/.myscript`

(notice the use of back-ticks, not apostrophes).
 
Back
Top