Hi gjoshi,

I have Mod2.pm:

#!/usr/bin/perl -w package Mod2; use strict; use warnings; use Mod3; require Exporter; our $VERSION = '0.1000'; our @ISA = qw/Exporter/; our @EXPORT_OK = qw (double sixtimes); sub double { return 2 *shift} sub sixtimes { my $val = double shift; return Mod3::triple($val); }
And Mod3.pm:
#!/usr/bin/perl -w package Mod3; use strict; use warnings; use Mod2; require Exporter; our $VERSION = '0.1000'; our @ISA = qw/Exporter/; our @EXPORT_OK = qw (triple fourtimes); sub triple { return 3 * shift} sub fourtimes { my $val = Mod2::double(shift); return Mod2::double($val); }
And my user program (usemod.pl) is as follows:
#!/usr/bin/perl use feature qw /say/; use strict; use warnings; use Mod2 qw /sixtimes/; use Mod3 qw /triple fourtimes/; for my $x (0..4) { say "$x * 3 = ", triple($x); say "$x * 6 = ", sixtimes($x); say "$x * 4 = ", fourtimes($x); say "$x * 6 * 4 = ", sixtimes (fourtimes($x)); }
This seems to work fine:
$ perl usemod.pl 0 * 3 = 0 0 * 6 = 0 0 * 4 = 0 0 * 6 * 4 = 0 1 * 3 = 3 1 * 6 = 6 1 * 4 = 4 1 * 6 * 4 = 24 2 * 3 = 6 2 * 6 = 12 2 * 4 = 8 2 * 6 * 4 = 48 3 * 3 = 9 3 * 6 = 18 3 * 4 = 12 3 * 6 * 4 = 72 4 * 3 = 12 4 * 6 = 24 4 * 4 = 16 4 * 6 * 4 = 96

Or did I miss something in your question?


In reply to Re: Nested Modules in perl by Laurent_R
in thread Nested Modules in perl by gjoshi

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.