Artem Khodush wrote:
>
> To be more specific, I'd like to not use eval in the def_x,
> and keep "use strict 'vars'" in the code below:
>
> package z;
> use strict 'vars';
>
> sub use_x
> {
> eval( 'print "$x\n";' );
> }
>
you need to tell Perl that $x is in package z
#!/usr/bin/perl -w
package z;
use strict 'vars';
sub use_x{ print ${"z::$_[0]"},"\n"; }
sub def_x{ ${"z::$_[0]"} = $_[1]; }
def_x("dog","good"); use_x("dog");
def_x("cat","bad!"); use_x("cat");
__END__
prints:
good
bad!
david
--
s$s*$+/<tgmecJ"ntgR"tgjvqpC"vuwL$;$;=qq$
\x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65
\x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72
\x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32
\x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74
\x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>