V
Volker Nicolai
Hi,
I have read a lot about use strict and the visibility of variables
but still can not understand why my following problem occurs:
I have this small script:
-------------------------------------------
#!/usr/local/bin/perl
#use strict; # _1_
use import_pack;
# use vars qw($p_hash); # _2_
# *p_hash = \%main:_hash; # _3_
# print "P_HASH: $:_hash{x} , $:_hash{y}\n"; # _4_
print "P_HASH: $p_hash{x} , $p_hash{y}\n"; # _5_
-------------------------------------------
and the module import_pack.pm:
-------------------------------------------
#!/usr/local/bin/perl
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(%p_hash);
%p_hash = (
x => 123,
y => 888,
);
1;
-------------------------------------------
If I run it without use stricts it is fine.
But if I use strict (_1_) then I need line _4_* instead of _5_,
otherwise I get:
Variable "%p_hash" is not imported at import_test.pl line 9
Neither the 'announcement' of %p_hash with line _2_* nor the typeglob
line _3_* helps and I don't have any idea why. I thought the typeglob must be
pretty much the same as using the full var name (with package) in the
print statement.
So where is the crux?
(* uncommented
Thanks for helping!
Volker
I have read a lot about use strict and the visibility of variables
but still can not understand why my following problem occurs:
I have this small script:
-------------------------------------------
#!/usr/local/bin/perl
#use strict; # _1_
use import_pack;
# use vars qw($p_hash); # _2_
# *p_hash = \%main:_hash; # _3_
# print "P_HASH: $:_hash{x} , $:_hash{y}\n"; # _4_
print "P_HASH: $p_hash{x} , $p_hash{y}\n"; # _5_
-------------------------------------------
and the module import_pack.pm:
-------------------------------------------
#!/usr/local/bin/perl
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(%p_hash);
%p_hash = (
x => 123,
y => 888,
);
1;
-------------------------------------------
If I run it without use stricts it is fine.
But if I use strict (_1_) then I need line _4_* instead of _5_,
otherwise I get:
Variable "%p_hash" is not imported at import_test.pl line 9
Neither the 'announcement' of %p_hash with line _2_* nor the typeglob
line _3_* helps and I don't have any idea why. I thought the typeglob must be
pretty much the same as using the full var name (with package) in the
print statement.
So where is the crux?
(* uncommented
Thanks for helping!
Volker