in reply to Nested Modules in perl

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?