Will this function do what I need?

The AM post already explained it pretty well: File::Spec generally just checks whether a string looks like an absolute pathname - it does not verify whether the file really exists or what its absolute pathname really is. For example, file_name_is_absolute("/tmp/../home") on a *NIX system will normally return true. If there is a symlink /tmp/badlink that points to a nonexistent location, file_name_is_absolute("/tmp/badlink") will still return true, because it looks like an absolute path. So if "what you need" is to determine whether a user entered something that looks like an absolute path, then yes, File::Spec is the right tool. (Note that File::Spec isn't completely "hands off" in terms of the filesystem in all of its functions, for example its rel2abs will use Cwd.)

To do filename resolution that consults the file system (and does stuff like resolve symlinks), see abs_path from Cwd. (I took it a step further and implemented detailed symlink chain resolution (e.g. if you've got symlink1→symlink2→symlink3→target) in my relink tool - PM node on that.)


In reply to Re: Determining if file path is absolute by haukex
in thread Determining if file path is absolute by nysus

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.