Hello,

What are the ways to create a variable at run-time?

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";' );
}

sub def_x
{
 # three ways to create $x:

 ${"z::x"}=123; # with this, use_x does not work with strict 'vars' 
                     # - says 'variable $x is not imported'

 *{"z::x"}=\123; # and with this too.

 # is there any other way short of
 eval( 'use vars qw( $x ); $x=123;' ); # works

}

def_x;
use_x;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to