Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Directories Help

by smunro16 (Initiate)
on Aug 25, 2008 at 14:16 UTC ( [id://706688]=perlquestion: print w/replies, xml ) Need Help??

smunro16 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
Just wondered if you could help me out on this one.

I have a directory "Util" within that i have various files which refer to each other.

I have perl script 1 which i did not create but is a Utility for a product im using.

I have perl script 2 which wrapps (takes input in from prompts) data and uses it in conjunction with perl script 1. This also reffers to file named apps as the source for the XML data to work with

I have 1 file named apps...It holds information (XML files) which are querried by My Perl Scipt 2

I have an ARGVS file for perl scipt 1 also.

I want to create a directory called "code" which can hold perl script 1 perl script 2 and the ARGV file yet still call upon the apps folder which is the directory before.

How do i go about doing this?

I know this is really hard to understand/ view but any help would be appretiated

Replies are listed 'Best First'.
Re: Directories Help
by moritz (Cardinal) on Aug 25, 2008 at 14:30 UTC
    When perl scripts use relative paths to find files, this path is usually (unless the author did some magic with Cwd or the like) relative to the current working directory, not to the directory in which the script lives.

    So probably all you have to do is to create your directory, move the scripts to that dir, but run it from the same directory as before (or chdir to that directory in your wrapper script prior to executing script 1).

    I hope I understood what you asked. If not, try to explain a bit more, and tell us what your actual problem is (creating a directory isn't complicated...).

      Hi thanks for the quick reply.
      I think you know what i want.
      This being the case how to i run the script from the same directory as before (when its in "code").
        I think you know what i want.

        No. I'm only guessing. That's why I ask.

        This being the case how to i run the script from the same directory as before (when its in "code").

        Use chdir. There's a reason why I gave you that link in my previous reply.

Re: Directories Help
by themage (Friar) on Aug 25, 2008 at 14:37 UTC
    Hi smunro16,

    I presume that your question is on how to get the path to the scripts.

    You have two ways to get it. The first is using $0, that will give you the path to the current perl script, se second is using use Find::Bin.

    If you choose to use $0:
    my $path=$0; $path=~s/[^/]+$//;


    $path will now have the path to the directory where your perl script is.

    Note, however, that if you chdir inside you perl script $0 may not be a valid path to you perl script, once it may be relative to you initial path.

    To know more about this you may want to read the thread How do I get the full path to the script executing?.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://706688]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found