On 03/28/2013 11:17 AM, *Shaji Kalidasan* wrote:
Greetings,
I am using the following module
[module]
package My::GoldenRock::Utilities;
use strict;
use warnings;
use base 'Exporter';
our @EXPORT_OK = qw(foo bar);
our %EXPORT_TAGS = (all => \@EXPORT_OK);
our $VERSION = 0.1;
sub foo() { print "Inside foo\n"; }
sub bar { print "Inside bar\n"; }
[/module]
#Please note that I am not using a return value (1 in this case) as the last
statement
[code]
use My::GoldenRock::Utilities 'bar';
print bar();
[/code]
[output]
Inside bar
1
[/output]
From where is the number 1 coming in the output. Earlier I mentioned '1' as
the last statement in the module and I thought '1' is printed in the output
owing to that. How to eliminate '1' from the output?
Please explain the intricacies of
use base 'Exporter';
our @EXPORT_OK = qw(foo bar);
our %EXPORT_TAGS = (all => \@EXPORT_OK);
Any pointers are greatly appreciated.
best,
Shaji
-------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to God.
-------------------------------------------------------------------------------
Your subroutine bar() has a print statement in it, that prints "Inside
bar" and a newline. bar() then returns the value of the last statement
(which is the "print" in this case). The print function returns true
when it succeeds, so it returns a "1" in this case. Your mainline code
then prints (with another print) the return value of
My::GoldenRock::Utilities::bar(). This is where you printed '1' comes from.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/