Home: Perl Programming Help: Beginner:
Cwd::abs_path V/S File::Spec->rel2abs



sriharsha_12
Novice

Mar 23, 2016, 3:13 AM


Views: 1339
Cwd::abs_path V/S File::Spec->rel2abs

I created a link 'date_link.txt' which is a link to 'date.txt' file. I'm trying to get the full path for 'date_link.txt'. When I try the following code,


Code
$f = 'date_link.txt'; 
say 'abs_path(): ' . Cwd::abs_path ($f);
say 'rel2abs(): ' . File::Spec->rel2abs ($f);

Output:
abs_path(): /home/.../test/date.txt
rel2abs(): /home/.../test/date_link.txt


rel2abs gives the required output. I was expecting both rel2abs & abs_path to return the same value. But abs_path returns the path of the real file. Isn't it the way it works?


FishMonger
Veteran / Moderator

Mar 23, 2016, 7:13 AM


Views: 1333
Re: [sriharsha_12] Cwd::abs_path V/S File::Spec->rel2abs

abs_path() documentation states:

Quote
Symbolic links and relative-path components ("." and "..") are resolved to return the canonical pathname


The documentation for rel2abs() does not make that statement so there's no reason to think that it would resolve symbolic links.


sriharsha_12
Novice

Mar 27, 2016, 10:49 PM


Views: 1322
Re: [FishMonger] Cwd::abs_path V/S File::Spec->rel2abs

Ok. Thanks.