in reply to Re: Creating variables while using 'strict'
in thread Creating variables while using 'strict'

I don't think that will help do what the author intended. The problem isn't creating new variables, it's creating new ones with dynamic names (and then being able to use them under strict). Using lexicals doesn't solve this:
# 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
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.

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
    Thanks for the clarification blokhead. This is exactly the problem I had in mind.