How to do I get the return code of a subroutine in a perl module if invoke the subroutine as standalone,
I have an module say TestExit.pm and in that i have a subroutine say myTest() which is returns 12, if i were to call the subroutine from
command line like
CASE:1 ( Without an explict exit in END routine )
perl -I/tmp/ -MTestExit -e 'myTest()'
echo $?
0
The above statement doesnot give me the return value of the subroutine ( which is 12 ) I get exit code as 0
Where as if I explicity do an exit in the END routine I am able to get the return code properly
Case2: ( With an explict an exit in END )
perl -I/tmp/ -MTestExit -e 'myTest()'
echo $?
12
Is there a way to pass an argument to the module or Is there a trick to get the exit code without modifying the END routing to an explict exit,
END routine exit is commented to get to match the case 1
TestExit.pm
package TestExit;
use strict;
use warnings;
our $status;
BEGIN
{
$status = 0;
}
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = (
'basic' => [qw( myTest
)],
);
Exporter::export_tags('basic');
sub myTest {
print "Called myTest routine, Setting return code as 12\n";
$status = 12;
}
1;
END {
print "RETURN VAL:$status \n";
#exit $status;
}
__END__