ken2 has asked for the wisdom of the Perl Monks concerning the following question:

Looking for some help on the following.

I have a script that now uses abs_path. Skinnied down version of the code is:

use Cwd 'abs_path'; my $szAbs = (abs_path $0); print "Abs path is $szAbs\n";

This works great on my machine and provides just what I'd expect:
    Abs path is C:/Program Files/xxxx/xxx.pl

My colleague gets the following error msg when executing the above:
    Cannot chdir to C:\Program Files\xxxx\xxx.pl:No such file or directory at C:\Program Files\xxxx\xxx.pl line 2

This must be due to different versions of Perl? or Cwd? Or?? Help!

Thanks,
Ken

Replies are listed 'Best First'.
Re: abs_path problem
by ikegami (Patriarch) on Dec 19, 2006 at 21:21 UTC
    Appears to be a bug in older versions of Cwd.
    >c:\progs\perl588\bin\perl 590788.pl Abs path is C:\Documents and Settings\ikegami\590788.pl >c:\progs\perl580\bin\perl 590788.pl Cannot chdir to 590788.pl: No such file or directory at 590788.pl line + 2

    Update: Apparently, it was fixed in Cwd version 2.18.

    Cwd 2.18 Thu Jun 24 08:22:57 CDT 2004 - Fixed a problem in which abs_path($arg) on some platforms could only be called on directories, and died when called on files. This was a problem in the pure-perl implementation _perl_abs_path(). - Fixed fast_abs_path($arg) in the same way as abs_path($arg) above.

    Update: According to Module::CoreList, Cwd with the bug fix (>= 2.18) has been included with all versions of Perl since (and including) Perl v5.8.5.

Re: abs_path problem
by madbombX (Hermit) on Dec 19, 2006 at 21:00 UTC
    Can you start by providing us with the information necessary to make that determination? ie: Which versions of Perl each of you have, which versions of the modules you have, etc.
Re: abs_path problem
by andyford (Curate) on Dec 19, 2006 at 21:16 UTC

    You cannot chdir to a file. chdir to a directory.

    Update: Sorry I thought OP was telling a fib and the colleague was running a different script.

    non-Perl: Andy Ford

      The function is supposed to return the absolute path to a file. He's not trying to chdir to a file.