0

I am just learning how to use Perl and while looking through the examples given on learn.perl.org/examples/, I came across this error on multiple example programs saying:

Can't locate Path/Class.pm in @INC (@INC contains: C:/Dwimperl/perl/site/lib C:/Dwimperl/perl/vendor/lib C:/Dwimperl/perl/lib .) at read_file.pl line 5. BEGIN failed--compilation aborted at read_file.pl line 5.

This is the code from each of the examples:

#!/usr/bin/perl
use strict;
use warnings;

use Path::Class;
use autodie; # die if problem reading or writing a file

my $dir = dir("/tmp"); # /tmp

my $file = $dir->file("file.txt");

# Read in the entire contents of a file
my $content = $file->slurp();

# openr() returns an IO::File object to read from
my $file_handle = $file->openr();

# Read in line at a time
while( my $line = $file_handle->getline() ) {
        print $line;
}

and:

#!/usr/bin/perl
use strict;
use warnings;

use Path::Class;

my $dir = dir('foo','bar'); # foo/bar

# Iterate over the content of foo/bar
while (my $file = $dir->next) {

    # See if it is a directory and skip
    next if $file->is_dir();

    # Print out the file name and path
    print $file->stringify . "\n";
}
ikegami
  • 367,544
  • 15
  • 269
  • 518
akrantz01
  • 628
  • 1
  • 9
  • 19
  • Possible duplicate of [What's the easiest way to install a missing Perl module?](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – ThisSuitIsBlackNot May 26 '16 at 00:38

1 Answers1

2

I don't know why you got the message you did; you should have received the following error message:

Can't locate Path/Class.pm in @INC (you may need to install the Path::Class module) (@INC contains: ...)

You are trying to use a module you haven't installed yet.

cpan Path::Class
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Could the module be installed but not present in the directories present in @INC? – gaganso May 26 '16 at 06:19
  • 1
    @SilentMonk, Yes, but unlikely, especially since he's using a version of Perl that was released just a week ago. If the OP comes back and says he just installed it and he's still getting the problem, it means either 1) he installed it in a non-default directory, and didn't tell `perl`, or 2) he installed it using a different `perl` (meaning it's still not installed for the `perl` in question). – ikegami May 26 '16 at 14:35