in reply to Module Style and Usage
Here's what I have so far:
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?# 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;
John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Module Style and Usage
by parv (Parson) on Sep 08, 2005 at 07:07 UTC |