Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   How do I find my runtime directory? (http://www.velocityreviews.com/forums/t24941-how-do-i-find-my-runtime-directory.html)

Joe Cosby 04-04-2004 07:18 PM

How do I find my runtime directory?
 

This seems like a simple thing, but I can't find anything in the "Perl
Cookbook" or the online Perl docs to answer this.

When a script runs from my host's server, the working directory
doesn't appear to be the directory the script is located in. (They
have Perl running under IIS, I don't know what versions).

I tried File::Spec->curdir() , but it just returns ".", which is
accurate, but not very helpful.

Does anyone know a way to do this?

--
Joe Cosby
http://joecosby.com/
pablo picasso well, some people try to pick up girls and they get called an asshole.
this never happened to pablo picasso. he could walk down your street and girls
could not resist his stare and pablo picasso never got called an asshole. the girls
would turn the colour of an avocado when he drove down their street in his eldorado.
he could drive down your street and girls could not resist his stare. pablo picasso
never got called the asshole. oh well be not schmuck, be not obnoxious, be not
bell-bottom bummer or asshole. this is the story of pablo picasso. he could walk
down your street and girls could not resist his stare, so pablo picasso never got
called an asshole. not like you. (j.richman)



Joe Cosby 04-04-2004 08:02 PM

Re: How do I find my runtime directory?
 
On Sun, 04 Apr 2004 12:18:09 -0700, Joe Cosby
<joecosby@SPAMBLOCKmindspring.com> wrote:

>
>This seems like a simple thing, but I can't find anything in the "Perl
>Cookbook" or the online Perl docs to answer this.
>
>When a script runs from my host's server, the working directory
>doesn't appear to be the directory the script is located in. (They
>have Perl running under IIS, I don't know what versions).
>
>I tried File::Spec->curdir() , but it just returns ".", which is
>accurate, but not very helpful.
>
>Does anyone know a way to do this?


Maybe I should clarify what I'm trying to accomplish a little.

I want to be have a relative directory structure within my code. For
instance, within a "code" directoy I have scripts, then a subdirectory
"templates" within "code" contains html templates.

I want to be able to read the templates by loading a file
"templates/templatename.htm", instead of having to hard-code
"e:\www\joecosby\code\templates\templatename.h tm" (the path on the
server) in the code I upload, ""C:\My
Documents\webpage\newstuff\code\templates\template name.htm" (the path
on my local machine) in the code before I upload it, etc.

I mean it's the same idea as using relative references versus absolute
references in HTML, it saves me from a huge amount of maintenance
work.

The perl environment seems to know what directory my script is running
from, when I get error messages they include the complete path to the
script, so if I could just chdir() to that directory at the start of
all my scripts that would at least be a workable solution.

--
Joe Cosby
http://joecosby.com/
"Now that I've inspired a character in a Godzilla movie, all I
really still desire is for several Ingmar Bergman characters to sit in a
circle and read my reviews to one another in hushed tones." - Roger Ebert


Jürgen Exner 04-05-2004 04:37 AM

Re: How do I find my runtime directory?
 
Joe Cosby wrote:
> When a script runs from my host's server, the working directory
> doesn't appear to be the directory the script is located in.


It would be a rare coincidence indeed if the script were located in the
current working directory.

> Does anyone know a way to do this?


perldoc Cwd

jue



Joe Cosby 04-10-2004 11:17 PM

Re: How do I find my runtime directory?
 
On Mon, 05 Apr 2004 04:37:29 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>Joe Cosby wrote:
>> When a script runs from my host's server, the working directory
>> doesn't appear to be the directory the script is located in.

>
>It would be a rare coincidence indeed if the script were located in the
>current working directory.
>
>> Does anyone know a way to do this?

>
>perldoc Cwd
>


Thanks for the help; what I would like to be able to do though, if
possible, would be to somehow determine the path where the script is
located.

I have a directory structure like this on the server:

top page directory
- Code (directory)
---- mail.pl

That is, inside the top directory is a subdirectory "code", and inside
that is "mail.pl".

When mail.pl is called though, the working directory is the top
directory. It would be useful, for a number of tasks, to be able to
determine the location of the script within the code base.

--
Joe Cosby
http://joecosby.com/
0x29A - opcode of the beast!


Gunnar Hjalmarsson 04-10-2004 11:33 PM

Re: How do I find my runtime directory?
 
Joe Cosby wrote:
> what I would like to be able to do though, if possible, would be to
> somehow determine the path where the script is located.


You can use $0 or $ENV{SCRIPT_FILENAME} for that.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Jürgen Exner 04-11-2004 12:32 AM

Re: How do I find my runtime directory?
 
Joe Cosby wrote:
[...]
> Thanks for the help; what I would like to be able to do though, if
> possible, would be to somehow determine the path where the script is
> located.


perldoc FindBin

jue



Joe Cosby 04-11-2004 01:18 AM

Re: How do I find my runtime directory?
 

foreach $reply (@responses)

thanks

blrk. I'm making jokes in Perl. That's really not a good sign.

--
Joe Cosby
http://joecosby.com/
EMBRACE the SUCKINESS



All times are GMT. The time now is 10:58 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.