mnperez has asked for the wisdom of the Perl Monks concerning the following question:
Both are using strict, the first, test.pl, seems to work fine -- the second, base.pm is where I am having difficulties.
The object is to pass a portion of the hash through to a function in the base module and have the base module create a variable, $oid_<itemfromhash>. When using strict and predeclaring all the possible variables that will be created at the top of the module, printing the variables after they are set yields nothing.
If I take off strict and either don't predeclare or predeclare with local(), I get data in the variables.
What am I doing wrong?
Files attached, thanks.
- Mike
test.pl: use lib qw(.); use base; use strict; my %OID = ( 'myoid' => { 'name' => 'myoid', 'type' => 'string', }, 'myoid2' => { 'name' => 'myoid2', 'type' => 'string2', }, ); my $buh = "myoid"; test($OID{$buh}); base.pm: use Exporter; use strict; no strict 'refs'; use vars qw(@EXPORT @ISA @EXPORT_OK); @EXPORT = qw(test); @ISA = qw(Exporter); my $oid_name; my $oid_type; sub test { my ($in) = @_; foreach my $item (keys %{ $in }) { print "(ITM) -> $item\n"; print "(VAL) -> $in->{$item}\n"; ${ "oid_$item" } = $in->{$item}; } print "oid_name is '$oid_name'\n"; print "oid_type is '$oid_type'\n"; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Odd problem with referencing
by jynx (Priest) on Mar 15, 2001 at 01:49 UTC | |
by frag (Hermit) on Mar 15, 2001 at 02:50 UTC | |
|
Re: Odd problem with referencing
by arturo (Vicar) on Mar 15, 2001 at 02:41 UTC |