in reply to Re: Creating variables while using 'strict'
in thread Creating variables while using 'strict'
strict requires that variables be predefined before their use, whether global or lexical. However, when dynamically creating variables of any kind, this can't be the case. You may be able to bend things a bit to get the new variables created, but you can't actually use those new variables in the rest of your strict-enabled program (it sounds like nedals wants to use strict as much as possible in the remainder of the code). Please correct me if I'm missing some clever way of creating dynamic lexicals.# trying to create a $dynamic_var use strict; my $var_name = 'dynamic_var'; my $$var_name = 'foo'; # doesn't compile my ${$var_name} = 'foo'; # nor does this eval "my \$$var_name = 'foo';"; # this runs fine, now $dynamic_var # exists in some scope print $dynamic_var, "\n"; # but this doesn't work in strict
I think a hash is the best way to go.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Creating variables while using 'strict'
by nedals (Deacon) on Jan 06, 2003 at 06:20 UTC |