How to create a variable dynamically?
From: Artem Khodush (greenkaa_at_mail.ru)
Date: 04/28/04
- Next message: Stephan Hochhaus: "Re: Why Perl"
- Previous message: Mauro: "sysopen fails"
- Next in thread: James Edward Gray II: "Re: How to create a variable dynamically?"
- Reply: James Edward Gray II: "Re: How to create a variable dynamically?"
- Reply: David: "Re: How to create a variable dynamically?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Wed, 28 Apr 2004 12:03:51 +0400
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;
- Next message: Stephan Hochhaus: "Re: Why Perl"
- Previous message: Mauro: "sysopen fails"
- Next in thread: James Edward Gray II: "Re: How to create a variable dynamically?"
- Reply: James Edward Gray II: "Re: How to create a variable dynamically?"
- Reply: David: "Re: How to create a variable dynamically?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|