- $dir
- Something you can open and you can do a file test on.
- C:/www/domain/docroot/articles/2008/08/10
- $file
- Something you can open and you can do a file test on.
- C:/www/domain/docroot/articles/2008/08/10/01.html
- $dirname
- 10
- But could also be 2008/08/10
- $filename
- Including any extension
- 01.html
- $path
- Banned.
- Ambiguous and half the time not what I expect and almost certainly not what I expected yesterday :-)
- $xxx_root
- Key, often used dirs in a “web space”
A config file might have$web_root C:/www $domain_root domain
A base class could have helper methods/assessors for each of the “roots”docroot docroot art_root articles pic_root pics
A dir, is a xxx_root, and possibly one or more dir names. A file is a dir with a file name on the end.Sub docroot{ my $self = shift; my $cnf = $self->cnf; return join( q{/}, $cnf->param(q{$web_root}), $cnf->param(q{$domain_root}), $cnf->param(q{docroot}), ); } sub art_root { my $self = shift; my $cnf = $self->cnf; return join( q{/}, $self->docroot, $cnf->param(q{art_root} ); }
Anything that needs to be in an html page is $href and $src etc.my $article_file = join( q{/}, $self->art_root, $art_dirname, $art_filename, );
What’s wrong with path? Take a selection of core modules:
File::Basename - Parse file paths into directory, filename and suffix.
File::Path - create or remove directory trees
File::Spec - portably perform operations on file names
I find it confusing to keep on top of what a path is in the different contexts. Throw base and suffix into the mix and I’m rereading the docs again for the umpteenth time. File::Spec’s abs2rel talks about $base and $path. And where did those trees come from? And what do you do with a suffix list?
I would use these modules more if I didn’t get into such a tangle. I invariably have helper methods with names that better fit the conventions I’ve outlined e.g. mkdir.
While far from perfect everything has been a lot smoother since banning path.
A plague on paths!
How do monks manage to avoid such confusion?
update: fixed the join syntax
update2: fixed the links
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File system nomenclature. Death to path!
by ikegami (Patriarch) on Aug 10, 2008 at 13:17 UTC | |
Re: File system nomenclature. Death to path!
by dragonchild (Archbishop) on Aug 11, 2008 at 02:26 UTC | |
Re: File system nomenclature. Death to path!
by hangon (Deacon) on Aug 10, 2008 at 13:32 UTC | |
by Anonymous Monk on Aug 11, 2008 at 01:38 UTC | |
Re: File system nomenclature. Death to path!
by graff (Chancellor) on Aug 10, 2008 at 22:52 UTC | |
Re: File system nomenclature. Death to path!
by repellent (Priest) on Aug 11, 2008 at 04:34 UTC | |
Re: File system nomenclature. Death to path!
by JavaFan (Canon) on Aug 11, 2008 at 08:56 UTC | |
Re: File system nomenclature. Death to path!
by Anonymous Monk on Aug 10, 2008 at 13:10 UTC | |
Re: File system nomenclature. Death to path!
by doom (Deacon) on Aug 14, 2008 at 18:39 UTC |