Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re (3): opening new file in different directory

by VSarkiss (Monsignor)
on Oct 23, 2001 at 19:24 UTC ( [id://120812]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: opening new file in different directory
in thread opening new file in different directory

Two things: First, depending on the server configuration, the script may or may not be executing in the directory in which the file is installed. It's not where the script is installed that matters, but the current directory of the Perl process that's executing your script.

Second, more importantly: if you depend on a particular path, don't assume you're starting there, chdir to that directory explicitly. It guarantees your paths and has negligible overhead. If you're worried about spelling out the directory name in your script, read it in from the environment or some such. But don't assume your script will always execute in the same place.

Replies are listed 'Best First'.
Re: Re (3): opening new file in different directory
by George_Sherston (Vicar) on Oct 23, 2001 at 19:37 UTC
    So wd you recommend, say, having a function that "sandwiches" each file operation between a pair of chdirs? I do quite a lot of reading and writing, but I also pick up a lot of files (templates and so on). At the moment I keep all the auxiliary files in the same dir as the script and refer to them by name only, no explicit path.

    /me scratches head and wonders whether I shd use explicit file paths for *everything* I refer to from my script. Wd that be considered good practice?

    § George Sherston

      Ah, I'll give you the best answer ever in computing:

      It depends.

      Explicit paths for everything in your program sounds like overkill, since you have to maintain the paths and may end up with big headaches if you ever move stuff around.

      Personally, I'd organize the files so I wouldn't have to do a lot of chdir'ing. Then set the path once and go about the rest of the business. But I don't want to make a blanket statement about how to organize files and i/o without knowing a whole lot more about what you're doing. (Not that I want to know -- I've got enough problems of my own. ;-)

      HTH

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-16 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found