NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
almost perfect (Score:1)
The one problem with this is that the root directory needs a trailing slash to be correct. The above approach results in $dir = '/', $file = 'foo', "$dir/$file" = '//foo' - it gets a double slash for an important special case. If you always leave the trailing slash, you can use "$dir$file" instead and $dir is correct. Using '/foo/bar/' as a directory name is perhaps a bit ugly but correct. (A doubled slash is also ugly but correct, so you choose whichever ugliness grates less.)
Reply to This
Re:almost perfect (Score:2)
Double slash makes it ugly to the OS; not having a slash between filename components makes it ugly to the programmer. I choose making it nice for myself.
Plus, how often do you need to represent the root directory in a variable? Do you write many temporary files there or anything? Or permanent files? :)
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers