I'm doing some more experimenting with moving from library (.pl) files and onto module (.pm) files and their creation and I'm wondering about style/usage.

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 &timestamp)]); sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } sub timestamp { my ($timer) = @_; my ($ret); $ret = localtime($timer); } # End of timestamp 1;

READMORE tags added by Arunbear


In reply to Module Style and Usage by ozboomer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.