in reply to Determining if file path is absolute

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.)

Replies are listed 'Best First'.
Re^2: Determining if file path is absolute
by nysus (Parson) on Nov 03, 2018 at 22:47 UTC

    OK, thanks for the additional clarification. I just need to verify that it looks like an absolute path. I was worried that the documentation was trying to say that if it looked like an absolute path on a local machine it might not look absolute on another machine.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      I was worried that the documentation was trying to say that if it looked like an absolute path on a local machine it might not look absolute on another machine.

      You don't need to worry, unless those two machines are on different OSes, e.g. Windows vs. *NIX, since File::Spec loads the appropriate OS-specific module under the hood. On a *NIX system, it will say C:\\foo isn't absolute (on a Windows system, it'll still say /foo is absolute).