develooper Front page | perl.beginners | Postings from May 2012

Change relative path to absolute path

Thread Next
From:
Zapp
Date:
May 11, 2012 02:15
Subject:
Change relative path to absolute path
Message ID:
4FACD880.6090901@Gmail.com
I have a path like
"/root/Tools/Log/../../Bin2/Patch/../Settings/ServerInfo/", and it's
absolute path should be "/root/Bin2/Settings/ServerInfo".
and I use these codes to get what I want.

my $my_str = "/root/Tools/Log/../../Bin2/Patch/../Settings/ServerInfo/";
Replace_it: $my_str =~ s#[^\./]+/\.\./##g
and goto Replace_it;
print $my_str . "\n";

Does anyone has a better idea?



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About