I have a task where I need to concatenate 2 pathnames: absolute + relative in perl. The following describes what I am trying to achieve:
dir1/dir2/dir3/ + ../filename => dir1/dir2/filename
dir1/dir2/dir3/ + ../../filename => dir1/filename
I have only solution that counts “..” in relative path, say X, then splits the absolute path into dirs and count them – Y and finally concatenates only Y-X dirs with filename. This seems too bulky and I wonder whether better solution exists (I am sure it does). Thank you in advance.
It even works with two relative URLS like the ones you have.