Re: convert a given dir name to its absolute path
by tirwhan (Abbot) on Dec 22, 2005 at 11:42 UTC
|
Take a look at File::Spec, the rel2abs method:
$abs_path = File::Spec->rel2abs( "../../etc" ) ;
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
| [reply] [d/l] |
|
|
the $abs_path is empty, can you check -
$abs_path = File::Spec->rel2abs( "../../");
print $abs_path,"\n";
I got this empty (??)
Could you please advice ?
Thanks
azaria
| [reply] |
|
|
| [reply] [d/l] |
|
|
$abs_path = File::Spec->rel2abs( "../../");
print "$abs_path\n
__OUTPUT__
/usr/local/bin/../..
So it works correctly on my platform (Linux with perl 5.8.4).
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
| [reply] [d/l] |
Re: convert a given dir name to its absolute path
by rinceWind (Monsignor) on Dec 22, 2005 at 12:12 UTC
|
use Cwd qw/abs_path/;
Note that whilst File::Spec->rel2abs may give you the right answer sometimes, abs_path will give you the canonical path. rel2abs works by platform specific string manipulation, but abs_path asks the operating system for the path, on some platforms by doing a chdir followed by a pwd.
--
Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ? (Missquoting Janis Joplin)
| [reply] [d/l] |
|
|
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] |
|
|
I checked the following code on Linux but the output was unfortunatly empty ?!!
--------------------------------
use Cwd qw/abs_path/;
$abs_path = File::Spec->rel2abs( "../../");
print $abs_path,"\n";
| [reply] |
|
|
opps I mixed two method.
Ignore my mail.
I will check this Cwd
| [reply] |
|
|