in reply to How to get relative path in perl?
I prefer Path::Class
use Path::Class qw( file ); print( file('A:\\B.CD(E)~!@#$%^&\\E\\F.txt') ->relative('A:\\B.CD(E)~!@#$%^&'), "\n" );
You could also use File::Spec::Functions
use File::Spec::Functions qw( abs2rel ); print( abs2rel('A:\\B.CD(E)~!@#$%^&\\E\\F.txt', 'A:\\B.CD(E)~!@#$%^&'), "\n" );
Both of the above return E\F.txt because .\E\F.txt is redundant. You can prepend .\ to the result if you insist on its presence.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get relative path in perl?
by kiinoo (Novice) on Jan 19, 2010 at 06:36 UTC |