Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Reloading modules more than once

by abaxaba (Hermit)
on Aug 04, 2002 at 07:14 UTC ( #187465=note: print w/replies, xml ) Need Help??

in reply to Reloading modules more than once

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187465]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2023-09-22 18:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found