in reply to convert a given dir name to its absolute path

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

Replies are listed 'Best First'.
Re^2: convert a given dir name to its absolute path
by azaria (Beadle) on Dec 22, 2005 at 12:10 UTC
    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

      There are bugs in File::Spec that have to do with relative and absolute paths. Some are recently fixed, some fixes are still in developer releases. This may be related. You might want to see if upgrading File::Spec helps. See the change log for details.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Executed in /usr/local/bin:

      $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