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;
In reply to Module Style and Usage by ozboomer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |