Seeing things like open(C,"C:\perl5\modules\my-stuff\sth"); made me shrivel and run away...
But now, I've been reading excellent tutorial on thread-safety, and there, absolute paths are a must. You're supposed to convert your old, non-thread safe, relative-path-using modules, into new, shiny, absolute-path-using jewels of thread safety.
The reason is understandable - different threads share single CWD, thus, for them not to step on each other toe, you're supposed to use absolute paths. This reason is fine, and hard to argue with...
How can I make this change, I've accumulated lot's of examples and fine reasons for avoiding absolut paths througout my life, and avoiding them became a second nature.
UPDATE Think about this as a case for accessing hierarchical databases (and typical filesystem is an example of such).
By using absolute path (be it hardcoded, or constructed with File::Spec->catfile($prefix, $relative);) you're reducing it to a flat space.
The filename "/fs/sth/db/category/subcategory/file" instead of address, becomes just a long name...
THAT is the evil pattern here, and THAT is the thing I'm having a hard time adjusting to.
This leads to inefficencies (with pattern
) you're going through filesystem hierarchy only once, withchdir($workdir); foreach ($files) { workOnFile(); }
you're going through it many times, which is costly.workOnSomeFile($cwd,$file); ... workOnSomeOtherFile($cwd,$file);
Java programmers tend to write sth like this: chdir("/some/dir1/dir2");..workOnFile("/some/dir1/dir2/file") which I find highly unelegant and slightly disturbing.
Do you know of a way to overcome a mental barrier before I can start writing code like that without feeling guilty?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best practices - absolute paths?
by graff (Chancellor) on Aug 13, 2005 at 15:03 UTC | |
|
Re: Best practices - absolute paths?
by jonadab (Parson) on Aug 13, 2005 at 11:48 UTC | |
|
Re: Best practices - absolute paths?
by sparkyichi (Deacon) on Aug 12, 2005 at 19:03 UTC | |
|
Re: Best practices - absolute paths?
by jdhedden (Deacon) on Aug 12, 2005 at 21:07 UTC | |
|
Re: Best practices - absolute paths?
by itub (Priest) on Aug 12, 2005 at 20:05 UTC | |
|
Re: Best practices - absolute paths?
by Joost (Canon) on Aug 12, 2005 at 20:52 UTC | |
by GrandFather (Saint) on Aug 13, 2005 at 05:58 UTC | |
by Eyck (Priest) on Aug 13, 2005 at 11:32 UTC | |
by Joost (Canon) on Aug 13, 2005 at 11:38 UTC | |
by Eyck (Priest) on Aug 15, 2005 at 05:44 UTC | |
|
Re: Best practices - absolute paths?
by nothingmuch (Priest) on Aug 16, 2005 at 18:21 UTC | |
|
Re: Best practices - absolute paths?
by anonymized user 468275 (Curate) on Aug 16, 2005 at 15:38 UTC | |
|
Re: Best practices - absolute paths?
by graff (Chancellor) on Sep 13, 2005 at 04:51 UTC |