While a little out of the target of my OP, I've found that Cwd actually has something that really cleans up a path dealing with all the symlink issues:
#!/usr/bin/perl use strict; use warnings; use Cwd 'abs_path'; my $somepath = "/var/log/../../home/poletti/../../etc/passwd"; print "starting path: [$somepath]\n"; print "abs_path : [", abs_path($somepath), "]\n" __END__ starting path: [/var/log/../../home/poletti/../../etc/passwd] abs_path : [/etc/passwd]
According to the docs:
abs_path my $abs_path = abs_path($file); Uses the same algorithm as getcwd(). Symbolic links and re +lative- path components ("." and "..") are resolved to return the c +anonical pathname, just like realpath(3).
This probably requires that the file actually lives in the filesystem, but most of the time it's what one wants. Thank you all for the contributions, anyway :)

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Re: Cleaning up a path by polettix
in thread Cleaning up a path by polettix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.