Creating a file in Perl

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Creating a file in Perl

Postby pyro_dude » 20. May 2010 07:23

I've been a long-time PHP user, but I'm just now making a move toward using Perl. I'm experimenting with it on my Windows machine, getting things coded up to use and eventually move to a hosted Linux box.

My issue is in creating a file in Perl. I can create it fine, but for some reason it's being created in the Apache directory (C:\xampp\apache) rather than the folder I'm running it in (C:\xampp\htdocs\pe).

I looked through apache's .conf and the extras\perl.conf file, and I didn't see anything that jumped out at me, so I'm wondering if I'm missing a setting somewhere.

Granted, I know I could rewrite the perl code to write the file to ">..\htdocs\pe\file.txt" but I'd rather keep it simple for portability's sake.


Thanks in advance!
pyro_dude
 
Posts: 3
Joined: 20. May 2010 07:09

Re: Creating a file in Perl

Postby Nobbie » 20. May 2010 12:47

pyro_dude wrote:I looked through apache's .conf and the extras\perl.conf file, and I didn't see anything that jumped out at me, so I'm wondering if I'm missing a setting somewhere.


Then you obviously overlooked the setting of "ServerRoot" which is the very first keyword in httpd.conf:

Code: Select all
ServerRoot "C:/xampp/apache"


On Windows Systems, this is the default directory for execution of CGI scripts (like Perl scripts). In PHP Moduled Environment, the default directory is the directory where the script is stored.

pyro_dude wrote:Granted, I know I could rewrite the perl code to write the file to ">..\htdocs\pe\file.txt" but I'd rather keep it simple for portability's sake.


The only way to get portability is to use absolute fully qualified pathnames in conjunction with the use of server variables (like DocumentRoot), for example (PHP Syntax):

Code: Select all
$filename = $_SERVER['DocumentRoot'].DIRECTORY_SEPARATOR.'pe'.DIRECTORY_SEPARATOR.'file.txt';


Instead of hardcoded 'pe' you may also use/parse the value of "SCRIPT_FILENAME" and/or "SCRIPT_NAME" variables

As far as i remember, the server variables in Perl are stored in the Environment (Perl does not have a SERVER-Array, but I did not use Perl since a long time). You will find out the proper syntax for Perl surely.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: Creating a file in Perl

Postby pyro_dude » 20. May 2010 16:42

No, I certainly didn't miss the ServerRoot keyword, I was just going off the description directly above it, rather than doing my own research.

Code: Select all
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.


I assumed that it was just where those were kept, and not where, for example, scripts were run. I assumed, if anything, that it would have dumped the files into the perl directory, so it took me a bit to find it in the apache folder.

Regardless, it doesn't look like I'll be able to change the ServerRoot keyword since it affects config files, etc, so I'm off to research the Perl constants.

Thanks for your help.
pyro_dude
 
Posts: 3
Joined: 20. May 2010 07:09

Re: Creating a file in Perl

Postby JonB » 20. May 2010 23:45

Most Perl scripts in this type of setup should go in cgi-bin if you are using XAMPP defaults and have not created VirtualHosts

Be sure to change the shebang line to "C:/xampp/perl/bin" or wherever you installed XAMPP/

My XAMPP testing server coughs up YaBB very reliably. 8)

http://bravo.newnetenterprises.com/cgi- ... b2/YaBB.pl

:mrgreen:

Good Luck
:shock:
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Creating a file in Perl

Postby pyro_dude » 21. May 2010 06:16

Alright. So, apparently I'm not very smart...Everything I've seen shows that I should just be able to use $ENV{'PATH'} or other system Environment variables. But no matter how I try to print them, I get nothing. Just a blank line, or a blank page, or whatever.

Code: Select all
#!C:\xampp\perl\bin
print $ENV{'PATH'};


If I run them in a Command prompt, I get no output. When I run it in my browser, I just get an empty page. Is there a setting somewhere I'm screwing up? What am I doing wrong? :?
pyro_dude
 
Posts: 3
Joined: 20. May 2010 07:09

Re: Creating a file in Perl

Postby JonB » 21. May 2010 07:49

#!C:\xampp\perl\bin


wrong slashes, Perl adapts the slashes. It 'knows' what environment you are in...

Be sure to change the shebang line to "C:/xampp/perl/bin" or wherever you installed XAMPP/

Good Luck
:shock:
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 179 guests