in reply to packages / modules in the same file
The first is that you don't need Exporter if you're doing OO or are in the same file. Exporter is if you want to make a repository of functions, then bring some of them into another file. If you're all in the same file and package, then everything has access to the right symbols.
If you're doing OO, then just do a PACKAGE->new just like normal. use is only to compile another file which has a certain naming convention, and bring it into your namespace. If you have a class in your file, just work with it as if it had been in another file and you'd use'd it.
The third is that you're not going back to the main package. You need to tell the interpreter where the first line to execute is. That's the first line in the main package. Try the following:
That should work just fine.package Foo; sub new { print "In Foo::new\n"; my $self = bless {}, 'Foo'; return $self; } package main; my $bar = Foo->new; print "$bar\n";
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jptxs) Re: packages / modules in the same file
by jptxs (Curate) on Nov 13, 2001 at 20:12 UTC |