I need to define multiple modules in the same file. I would like to do something like the following:
package FooObj {
sub new { ... }
sub add_data { ... }
}
package BarObj {
use FooObj;
sub new {
...
# BarObj "has a" FooObj
my $self = ( myFoo => FooObj->new() );
...
}
sub some_method { ... }
}
my $bar = BarObj->new();
However, this results in the message:
Can’t locate FooObj.pm in @INC …
BEGIN failed…
How do I get this to work?
Drop the
use. Seriously.usetells perl to read in the code from another file, which you don’t need to do because the code is in the same file.