Your answer to your own question is exactly right. It is because you are
using the second module through a reference to an object of the type
"Schedule".  Look in the "new" method of the "Schedule" object. You will
see a line in that method that blesses a reference to a data structure
into the package "Schedule" (In fact the function call in new that does
this is called "bless"!) Without a blessed reference to scope your
function call "trace" into the "Trace" package perl automatically looks
in the "main" package. However once you made the "trace" function
available for export via Exporter and the EXPORT_OK array a "use Trace
qw(trace)" brings that function into the "main" namespace and thus perl
can see the function.

Cheers!

|b 

On Wed, 2003-06-25 at 19:39, Rob Richardson wrote:
> Greetings!
> 
> I wrote the following trivial module:
> 
> package Trace;
> 
> sub trace
> {
>       my $message = shift;
>       open (TRACE, ">>c:\\indigoperl\\htdocs\\data\\trace.log") or die
> "Could not open trace file: $!\n";
>       print TRACE $message;
>       close TRACE;
> }
> 
> my $motto = "Who invented this furshlugginer language anyway?";
> 
> 
> I used it in the following even more trivial script:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> use Trace qw(trace);
> 
> trace ("This is from the tracetest program.\n");
> 
> 
> As you are no doubt aware, this didn't work.  Perl complained that it
> didn't know about &main::trace().  I modifed the module by adding the
> following lines after "package Trace":
> 
> require Exporter;
> @ISA = qw(Exporter);
> @EXPORT_OK = qw(trace);
> 
> Once I had those lines in, the script worked.
> 
> 
> In the train schedule script that you are no doubt sick of hearing
> about by now, my main program has the following lines:
> 
> use Schedule;
> my $theSchedule = new Schedule;
> $theSchedule->Load("somefile.csv");
> 
> The file schedule.pm has a line that says, "package Schedule;", but no
> use of the Exporter module.  The other modules I am using to represent
> other objects in the system don't use Exporter either.  Yet I can use
> the objects and their methods without prefacing them with a symbol
> name.  Why don't I need a package name with them?  Is it because I am
> using them in an object-oriented way?
> 
> Thanks!
> 
> RobR
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to