ozboomer has asked for the wisdom of the Perl Monks concerning the following question:
The attached code has a reference number beside each line in the main code. To try things out, uncomment each of the #1 lines, or the #2 lines, etc. I know all of the lines of code work Ok but is there an 'accepted standard'?
My *preference* would be to use the fully-specified function name in a module (Option #2) but I can see how that might be cumbersome - hardly any of the (non-OOP) CPAN modules use the fully-specified convention. It seems like most of them use Option #3... but I like Option #2 in terms of documentation.
How do other people prefer to write.. and read... their/others' code?
Many thanks for your thoughts.
John
# ---- # Main Code require 'mylib.pl'; # [ 1 ] #use MyModule; # [ 2 ] #use MyModule qw(:All); # [ 3 ] printf("timestamp: %s\n", mylib::timestamp(time)); # [ 1 ] #printf("timestamp: %s\n", MyModule::timestamp(time)); # [ 2 ] #printf("timestamp: %s\n", timestamp(time)); # [ 3 ] # ---- # mylib.pl package mylib; #use Time::Local; sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } sub timestamp { my ($timer) = @_; my ($ret); $ret = localtime($timer); } # End of timestamp 1; # ---- # MyModule.pm package MyModule; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(func1 func2 timestamp); %EXPORT_TAGS = ( DEFAULT => [qw(&func1)], Both => [qw(&func1 &func2)], All => [qw(&func1 &func2 ×tamp)]); sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } sub timestamp { my ($timer) = @_; my ($ret); $ret = localtime($timer); } # End of timestamp 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Module Style and Usage
by xdg (Monsignor) on Sep 07, 2005 at 08:55 UTC | |
|
Re: Module Style and Usage
by hv (Prior) on Sep 07, 2005 at 10:30 UTC | |
|
Re: Module Style and Usage
by parv (Parson) on Sep 07, 2005 at 08:53 UTC | |
|
Re: Module Style and Usage
by Smylers (Pilgrim) on Sep 07, 2005 at 13:23 UTC | |
by Tanktalus (Canon) on Sep 07, 2005 at 14:30 UTC | |
|
Re: Module Style and Usage
by ozboomer (Friar) on Sep 07, 2005 at 22:22 UTC | |
|
Re: Module Style and Usage
by ozboomer (Friar) on Sep 08, 2005 at 03:07 UTC | |
by parv (Parson) on Sep 08, 2005 at 07:07 UTC |