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

I get the error "Undefined subroutine &File::Spec::rel2abs called at noname.pl line 5." when I execute the following code:

use warnings; use strict; use File::Spec; my $path = File::Spec::rel2abs ('.');

ppm reports the following:

Name: File-Spec Version: 0.82 Author: Barrie Slaymaker (barries@slaysys.com) Title: File-Spec Abstract: portably perform operations on file names Location: ActiveState PPM2 Repository Available Platforms: 1. MSWin32-x86-multi-thread-5.8

Any idea why this should be failing and how I can either fix the problem or another way I can achieve the same (relative path to abs path) result?


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re: Trouble using File::Spec::rel2abs with Windows
by blazar (Canon) on Jul 29, 2005 at 09:48 UTC
    Wild guess - from perldoc File::Spec:
    Since File::Spec is object oriented, subroutines should not be called directly, as in: File::Spec::catfile('a','b'); but rather as class methods: File::Spec->catfile('a','b'); For simple uses, File::Spec::Functions provides convenient functional forms of these methods.
    HTH

      Argh! That sums up most of my day!

      You are exactly right and I now recall reading that in the docs too! Thank you.


      Perl is Huffman encoded by design.
Re: Trouble using File::Spec::rel2abs with Windows
by bart (Canon) on Jul 29, 2005 at 10:08 UTC
    Just use File::Spec::Functions. Much easier than messing with those class method calls.
    use File::Spec::Functions qw(rel2abs); my $path = rel2abs('.');
Re: Trouble using File::Spec::rel2abs with Windows
by marto (Cardinal) on Jul 29, 2005 at 09:53 UTC
    Try
    use warnings; use strict; use File::Spec; my $path = File::Spec->rel2abs ('.');
    From the documentation.
    Update: curse this lag

    Hope this helps.

    Martin