PDA

View Full Version : using modules in Objects


gelse
10-02-2007, 10:54 AM
edit:
forget my question, i just found out myself.
main::logfile("foo");
did it.



Hello there!

I guess this is kinda noob question ...

I tried to search and trial/error my Problem, but it seems as if nothing works.

I have an external module (called Common.pm) with several subroutines (for writing logs, accessing DB, etc).
I can easily just put 'use Common' into my scripts, and it works like a charm.

Now i have my first Problem which i best solve with OOP - so i created my first Class, as the manuals say - a package within the script which i want to use, looks like this:
#!/usr/bin/perl -w
use Common;
# ... several other uses and thingies
# ... script code which uses the object
exit(0);

package Set;
BEGIN {
use Common;
}

sub new {
# ...
}

sub test {
# ...
# ver 1
Common::logfile("foo");
# ver 2
logfile("bar");
}
END {
}

the sub 'logfile' is defined in the Common.pm which resides in the same directory, and works fine in the main area of the script.
but within the object it seems as if it just cant find the subroutine.

So my question - how can i access subroutines in an external module from within an object?

thanks in advance!

KevinADC
10-03-2007, 08:08 PM
Why are you not just loading the Common module in the other module? Using "main::function" is rather unusual.