On Friday, Sep 26, 2003, at 18:07 US/Pacific, [EMAIL PROTECTED] wrote: [..]
[..]Can someone just point the way? Lets say i want to create a file in lib/favfuncs.pl. I would call funcs in favfuncs.pl in my other perl progs.
Dan has clearly pointed you in the right direction,
You will want to put them in a file named
favfuncs.pm
so that it will be simpler to
use favfuncs ;
because 'use' is looking for files that are suffix'd as 'pm'.
Another rule to keep in minds is that 'all low case' is reserved for 'pragma' - so it is best to make that a mix of upper and lower case - per the documentation
use FavFuncs.
Hence the file would be FavFuncs.pm, and the first line would be declaring the package.
package FavFuncs;
at that point you need to decide whether you want to be exporting the 'names' of your functions/subs into the code that will be using it - hence how to do 'Exporter' cf: perldoc Exporter - but you will also want to read up on perldoc h2xs - since it will help making the basic 'framework' for you.
If you are just providing a stack of functionality, you can still use the 'OO-ish' approach, so you would want say
#--------------------------------------------------------- # our constructor - plain vanilla new #--------------------------------------------------------- sub new { my $type = shift; my $class = ref($type) || $type; my $self = {}; bless $self, $class;
} # end of our simple new
#--------------------------------- # so that AUTOLOAD finds one here
sub DESTROY {}
which of course will require that you 'tweek' any of your basic functions which took arguments from the form:
sub fon_gu_lea { my ($var1,$var2,$var3) = @_; .... }
into the 'more complex'
sub fon_gu_lea { my $me = shift; my ($var1,$var2,$var3) = @_; .... }
{ for real fun, actually READ the perl module CGI.pm with perldoc -m CGI - there is some serious rocket science... }
I use $me because it is two letters, self and this are four, and that is way too much typing.
Now, yes, I know you asked about ONLY 'functions' - but as I noted above, to make a module with fon_gu_lea() and simply export it into the callers code, is actually a bit more work in some respects. Where as this way while it may seem like a lot of upfront work and all you really get is the simpler transition from
my $foo_bar = fon_gu_lea(@arglist);
and this appears to be transitioning into
my $funkMgr = new FavFuncs; my $foo_bar = $funkMgr->fon_gu_lea(@arglist);
when you get into the place where you have finished arguing with yourself about where to cache which sets of functionality, and whether or not to make classes that pass along by inheritence the base set of methods, and then the sub_classes add in the additional ones, and... and... and....
my $funkMgr = new Foo::Bar::Baz::FavFuncs; my $foo_bar = $funkMgr->fon_gu_lea(@arglist);
will seems a reasonable exchange.
But you will probably want to check out Randall Schwartz's new book about learning perl modules, references, et al...
ciao drieux
---
Remember if you play fairways and greens, you really only need the bigDog, a seven iron, and a putter. But otherwise you will need to get the rest of the woods, and the irons, and then get a caddy.... But always remember,
Never play golf with anyone who brought their own golf green.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]