in reply to Re: How to create a reusable routine ?
in thread How to create a reusable routine ?
Soo, @EXPORT_OK just tells what we can import explicity:
And @EXPORT set what the package export when you don't paste anything:use nu qw( &some_funtion $var $array %etc ) ;
Take a look in the documentation of Export: http://www.perldoc.com/perl5.8.0/lib/Exporter.htmluse nu ;
Other thing, try to build a pure Object-Oriented module, soo you will be able to use it in any type of application (console, GUI, CGI, mod_perl, etc...). One bad thing that you are doing is the action variablr, dependent of the arguments paste when the applications is executed by console.
Here's a simple example to start building an OO module:
To use this module and create an object:package FOO ; use strict qw(vars); use vars qw($VERSION) ; $VERSION = '0.01' ; sub new { ## The class name: my $class = shift ; ## Arguments when creating the object: my ( $arg1 , $arg2 , @rest ) = @_ ; ## Define from what package this object will be: my $this = bless({} , $class) ; ## Define some internal value/attribute in the object: $this->{FOO} = $arg1 ; ## Return the created object: return $this ; } sub methodx { ## The object reference: my $this = shift ; ## Arguments of this method: my ( $arg1 , $arg2 , @rest ) = @_ ; ... } 1;
use FOO ; my $foo = new FOO("some args") ; my @returned = $foo->methodx("other args") ;
Graciliano M. P.
"Creativity is the expression of the liberty".
|
|---|