laziness, impatience, and hubris | |
PerlMonks |
Re: How to convert Perl file to a perl module(.pm file).by tobyink (Canon) |
on Nov 02, 2012 at 15:32 UTC ( [id://1001998]=note: print w/replies, xml ) | Need Help?? |
The trivial answer is to just rename it, and make sure it returns a true value (this is usually done by making sure the last line of code is "1;"). More generally you probably want to:
Here's an example script...
You could refactor it into a module like this:
Which could be used like this...
After that, something to consider is making your code more object-oriented, thus allowing people to subclass it, overriding parts of its functionality.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
In Section
Seekers of Perl Wisdom
|
|