I guess my first question: Are these
required files just collections of subroutines with a
.pm extention, or are they actual packages? Against my gut, I'll assume that they're packages, based on the
.pm extension in the filename.
Based on that assumption:
#!/perl
use strict;
use lib qw(/path/to /another/pathto);
use diffrent;
use something;
something::todo(arg1,arg2);
diffrent::todo(arg3,arg4);
Another option is to take advantage of
polymorphism, and some OOP. This can especially be an attractive choice if you find yourself with a lot of similar code between the two files:
package something;
@something::ISA=qw(basePack);
sub todo
{
#something::todo code in here
}
package diffrent;
@diffrent::ISA=qw(basePack);
sub todo
{
#diffrent::todo code in here
}
package basePack
sub new
{
return bless({},shift);
}
sub act
{
my $self=shift;
$self->todo(@_);
}
#package main.
#!/perl
use strict;
use lib qw(/path/to /another/pathto);
use diffrent;
use something;
my $something=new something;
my $diffrent = new diffrent;
$something->act($arg1, $arg2); #something::todo;
$diffrent->act($arg3,$arg4); #diffrent::todo;
Of course, all of this can be averted. If you know when to "reload" sub todo, then you ought to know when it should be called. Just rename one of the todo subs to something else.
ÅßÅ×ÅßÅ
"It is a very mixed blessing to be brought back from the dead." -- Kurt Vonnegut
|
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.