Bah, that is ugly! I'd do it another way.print File::Spec->rel2abs( File::Spec->catdir( dirname(__FILE__), File::Spec->updir(), ) );
Did you know that rel2abs takes an optional second parameter, the reference directory? So, a much cleaner way (IMO) to do this is:
Even though you probably can just doprint File::Spec->rel2abs( File::Spec->updir, dirname(__FILE__) );
You may probably even drop the rel2abs call, in this specific case, as __FILE__ would appear to return an absolute path – even though I don't quite trust that to always be the case.print dirname(dirname(File::Spec->rel2abs(__FILE__)));
print dirname(dirname(__FILE__)); # ?? Is this reliable?
All code snippets, mine and yours, show the same string in my test.
In reply to Re^3: Platform Independent Directory Traversal
by bart
in thread Platform Independent Directory Traversal
by wind
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |