bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
I'm discovering the benefits of reusable code. My question is this: do I have to put the code in a package or can it just be a file that ends with 1;? I have done it both ways, but the package method requires a little extra code. I have read in Programming Perl that the package method protects the namespaces, but what else? Thanks.
Main (without using package):
use Common.pm; my $returnvalue = somesub();
Common.pm:
sub somesub { ...create value... return($value); } 1;
Main (with package):
use Common.pm; my $returnvalue = Common->somesub();
Common.pm:
package Common; sub somesub { ...create value... return($value); } 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Package vs. plain file
by crashtest (Curate) on Jun 04, 2005 at 17:29 UTC | |
Re: Package vs. plain file
by fishbot_v2 (Chaplain) on Jun 04, 2005 at 19:59 UTC | |
Re: Package vs. plain file
by djohnston (Monk) on Jun 04, 2005 at 19:46 UTC | |
Re: Package vs. plain file
by Ninthwave (Chaplain) on Jun 04, 2005 at 17:05 UTC | |
Re: Package vs. plain file
by jhourcle (Prior) on Jun 04, 2005 at 17:07 UTC | |
Re: Package vs. plain file
by tlm (Prior) on Jun 04, 2005 at 21:23 UTC |