I'm confused about the path you're taking here (pun intended). Are you still working on Creating a bash script "on the fly" from a few days ago? If so, then I have to say I think you're creating yourself an XY Problem. I've already pointed you to:
Also, I'm not sure what you're testing with (index($link,"/") == -1)? Note links to directories don't need to end oncontain a slash; you won't know what the link is pointing to until you check the filesystem. (Update: Looking at your code again, I see a couple more ways in which certain symlinks would break it.)
But what if the link is relative (for example ../../abc)?
You're discovering one of the many intricacies of resolving symlinks. As explained in the documentation of File::Spec's canonpath: "If /foo on your system is a symlink to /bar/baz, then /foo/../quux is actually /bar/quux, not /quux as a naive ../-removal would give you."
Sorry, but based on my interpretation of everything above, I would strongly suggest that you first learn more about symlinks and handling filenames before trying to implement this. Even though I did a lot of research and testing when I wrote the relink script, and I trust my own code, I'm still not sure I've fully understood every little detail and edge case that could happen. It's not an easy topic.
But anyway, I suggest that even before that, maybe you could explain why the above solutions are not acceptable to you, and why you need to reinvent this particular wheel? I'm sure we could come up with a better solution for your actual problem.
If you're still working on Creating a bash script "on the fly", i.e. you're just trying to replicate a directory structure, then could you explain why a solution such as rsync, or simply copying over the links, is not sufficient? (You do know you can get most *NIX tools to not follow symlinks, right?)
Minor edits.
In reply to Re: Getting all subpaths from a path
by haukex
in thread Getting all subpaths from a path
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |