I been reading through Perl Objects, References & Modules, one of the exercises asks for the creation of a library with two simple subs. The 2nd exercise then wants to use the library that was just created to print out the date. The model answer is as follows:

#!/usr/bin/perl -w

package Oogaboogoo::date;

use strict;

my @months = qw | diz pod bod rod sip wax lin sen kun fiz nap dep |;
my @days = qw | ark dip wap sen pop sep kir |;

sub day
{
    my $num = shift @_;
    
    die "$num is not a day number" unless $num >= 0 && $num <= 6;
    
    $days[$num];
}

sub month
{
    my $num = shift @_;
    
    die "$num is not a month number" unless $num >= 0 && $num <= 11;
    
    $months[$num];
}

1;

Heres the code for the 2nd exercise:

#!/usr/bin/perl -w

unshift @INC, 'C:\perlexamples\oorefmods\Oogaboogoo';
use strict;
require Oogaboogoo::date;

my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime;

my $day_name = Oogaboogoo::date::day($wday);
my $mon_name = Oogaboogoo::date::month($mon);
$year += 1900;
printf "Today is the %s, %s %s, %s\n", $day_name, $mon_name, $mday, $year;

Whenever I try to run the 2nd exercise i get the following error:
---------- Capture Output ----------
> "C:\perl\bin\perl.exe" ex2-2.pl
Can't locate Oogaboogoo/date.pm in @INC (@INC contains: C:\perlexamples\oorefmods\Oogaboogoo C:/Perl/lib C:/Perl/site/lib .) at ex2-2.pl line 5.

> Terminated with exit code 2.

I'd appreciate any help I can get.
Thanks

I think the problem with this line:

require Oogaboogoo::date;

is that the :: is a directory path, which is why you get the error message:

Can't locate Oogaboogoo/date.pm

rename the module to 'date.pm' and put it in the Oogaboogoo directory and I think it will work.

I think the problem with this line:

require Oogaboogoo::date;

is that the :: is a directory path, which is why you get the error message:

Can't locate Oogaboogoo/date.pm

rename the module to 'date.pm' and put it in the Oogaboogoo directory and I think it will work.

Although the method above works, I figured out what I should have done. require Oogaboogoo::date; should be require 'Oogaboogoo/date.pl'; this would also mean that I wouldn't have to rename date.pl to date.pm.

Comments
coming back with the solution is a good thing

they really do the same thing but in a differnt way. Either way will work. My way showed why the code you had was not working, but going with 'require' and replacing '::' with '/' and .pm with .pl is fine.

This article has been dead for over six months. Start a new discussion instead.