in reply to First Perl Module!!
As has been pointed out, using the arrow operator passes the class name (or object instance, if you have one) as the first argument to the method. However, you may not want to dive into OO Perl just yet. In that case, call the subroutine as a function, not as a method. That means that you change the '->' to '::'.
use Foo; my $name = Foo::test("TEST"); print "Name: $name\n";
Once you get that down, you can start learning about Exporter and learn to export the selected functions you need:
package Foo; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = ( 'test' ); sub test { my $thing = shift; return $thing; }
With that code anything that can be accessed through your package (such as package variables and subroutines) can be exported to your class by listing the item in your "import list":
use Foo qw(test); my $name = test("TEST"); print "Name: $name\n";
See the documentation for Exporter for more information. Have fun!
Cheers,
Ovid
New address of my CGI Course.
|
|---|