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
    I'm using the second one, because Path::Class is not found and i'm not going to download one.. Thanks very much, that solved my problem!