Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6116341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:11:44+00:00 2026-05-23T15:11:44+00:00

I have a task where I need to concatenate 2 pathnames: absolute + relative

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:11:45+00:00Added an answer on May 23, 2026 at 3:11 pm
    $ perl -MURI -E'say URI->new($ARGV[1])->abs($ARGV[0]);' \
        http://foo.com/dir1/dir2/dir3/ ../filename
    http://foo.com/dir1/dir2/filename
    
    $ perl -MURI -E'say URI->new($ARGV[1])->abs($ARGV[0]);' \
        http://foo.com/dir1/dir2/dir3/ ../../filename
    http://foo.com/dir1/filename
    

    It even works with two relative URLS like the ones you have.

    $ perl -MURI -E'say URI->new($ARGV[1])->abs($ARGV[0]);' \
        /dir1/dir2/dir3/ ../filename
    /dir1/dir2/filename
    
    $ perl -MURI -E'say URI->new($ARGV[1])->abs($ARGV[0]);' \
        /dir1/dir2/dir3/ ../../filename
    /dir1/filename
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following task: I need to connect to FTP server and download data
I have a task I need to perform, do_stuff(opts) , that will take ~1s
I have a rake task I need to run as a daily job on
I have a task where I need to translate a DataTable to a two-dimensional
I have a jQuery function already to perform the task I need but is
I have submitted a task using executors and I need it to stop after
I have next task: I need to load the same file into my web
Task is: I have task queue stored in db. It grows. I need to
Using MySql 5, I have a task where I need to update one table
I'm making a task-based program that needs to have plugins. Tasks need to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.