このスレッドに戻って参照すると、モジュールからデータをエクスポートする方法に苦労しています。1つの方法は機能していますが、実装したい他の方法は機能していません。
問題は、スクリプトの2番目のメソッドが機能しない理由です。(これは配布専用だと思うので、モジュールをh2xsしませんでした)
Perl 5.10/Linuxディストリビューション
モジュールmy_common_declarations.pm
#!/usr/bin/perl -w
package my_common_declarations;
use strict;
use warnings;
use parent qw(Exporter);
our @EXPORT_OK = qw(debugme);
# local datas
my ( $tmp, $exec_mode, $DEBUGME );
my %debug_hash = ( true => 1, TRUE => 1, false => 0, FALSE => 0, tmp=>$tmp, exec=>$exec_mode, debugme=>$DEBUGME );
# exported hash
sub debugme {
return %debug_hash;
}
1;
脚本
#!/usr/bin/perl -w
use strict;
use warnings;
use my_common_declarations qw(debugme);
# 1st Method: WORKS
my %local_hash = &debugme;
print "\n1st method:\nTRUE: ". $local_hash{true}. " ou : " . $local_hash{TRUE} , "\n";
# 2nd Method: CAVEATS
# error returned : "Global symbol "%debug_hash" requires explicit package name"
print "2nd method \n " . $debug_hash{true};
__END__
事前にThx。