# Foo.pm
package Foo;
use warnings;
use strict;
use parent 'Exporter';
our @EXPORT_OK = qw(hello get_hello);
my $hello = hello('evaluated during module inclusion');
sub hello {
my $h = shift;
return $h;
}
sub get_hello {
return $hello;
}
print 'from package ', __PACKAGE__, " during use: '$hello' \n";
1;
####
# use_foo_1.pl
use warnings;
use strict;
use Foo qw(hello get_hello);
hello('test');
print 'from package ', __PACKAGE__, " during execution: '", get_hello, "' \n";
####
c:\@Work\Perl\monks\Anonymous Monk\1207065>perl use_foo_1.pl
from package Foo during use: 'evaluated during module inclusion'
from package main during execution: 'evaluated during module inclusion'
####
# Foo.pm
package Foo;
use warnings;
use strict;
use parent 'Exporter';
our @EXPORT_OK = qw(hello set_hello get_hello);
my $hello = hello('evaluated during module inclusion');
sub hello {
my $h = shift;
return $h;
}
sub get_hello {
return $hello;
}
sub set_hello {
return $hello = shift;
}
print 'from package ', __PACKAGE__, " during use: '$hello' \n";
1;
####
# use_foo_2.pl
use warnings;
use strict;
use Foo qw(hello set_hello get_hello);
hello('test -- this goes nowhere (void context)');
printf "A: from package %s during execution: '%s' \n",
__PACKAGE__, get_hello;
set_hello("now we're getting somewhere!");
printf "B: from package %s during execution: '%s' \n",
__PACKAGE__, get_hello;
####
c:\@Work\Perl\monks\Anonymous Monk\1207065>perl use_foo_2.pl
from package Foo during use: 'evaluated during module inclusion'
A: from package main during execution: 'evaluated during module inclusion'
B: from package main during execution: 'now we're getting somewhere!'