Well, I've had a go... and I'm managing to get some of this module code working and I'm understanding it as well :) Thus, I've decided to code-up some example usage to illustrate what I've found out.

Here's what I have so far:

# Q.pl - mainline code use Q2 qw($myfile func1 $SM_HDR_REC); # ---- printf("\$Q2::myfile: >$Q2::myfile<\n"); printf("\$Q2::myport: >$Q2::myport<\n"); # Not exported but still # usable by fully-specifying printf("\$myfile: >$myfile<\n"); # Ok 'coz it's exported printf("\$myport: >$myport<\n"); # Unknown 'coz not exported printf("SM_HDR_REC: >$SM_HDR_REC<\n"); # Declared 'our' in Q2.pm # ---- $buf = "test_string"; printf("\nFn call into temp var:\n"); printf("String before: %s\n", $buf); $newbuf = func1($buf); # Works! printf("String after: %s\n\n", $newbuf); $buf = "test_string"; printf("Fn call only:\n"); printf("String before: %s\n", $buf); printf("String after: %s\n\n", func1($buf)); # Doesn't work!? # Q2.pm - module code package Q2; use strict; use Exporter; # ---- use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw($myfile &func1 &func2 $SM_HDR_REC); %EXPORT_TAGS = (DEFAULT => [qw(&func1)], all => [qw(&func1 func2 $myfile)]); # ---- use vars qw($myfile $myport); $myfile = 'FRED.DAT'; # Used locally and exported (above) $myport = "OPA0:"; # Used locally but not exported # ---- our $SM_HDR_REC = "HDR"; # ---- sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } END { }; 1;
The only question I have is the call to func1 -- the two calls in the mainline program above give different results. Is there something with how the function is being called or exported... or am I missing something obvious?


John


In reply to Re: Module Style and Usage by ozboomer
in thread 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.