On Fri, Nov 14, 2003 at 12:25:41PM -0800, david wrote: > Douglas Houston wrote: >> >> I am trying to initialize a dynamically-named array > > this normally can't be done cleanly and is generally not recommanded given > there are other ways to accomplish bascially the same thing. but if you are > here to see if it can be done at all, you might want to try something like: > > #!/usr/bin/perl -w > use strict; > > my $name = shift; > > eval <<CODE; > no strict; > @ $name=1..3; > print "\$_\\n" for(@ $name); > CODE
Sigh... :-) The point is not that *symrefs* are inherently bad. The point is that turning data into variable names can cause huge, nightmarish maintenance problems. Even though your code doesn't have any symbolic references, it can still cause all the same maintenance problems... and it's so much uglier than just using symrefs in the first place! > while(my($k,$v) = each %::){ > next unless($k =~ /^$name$/); > local *sym = $v; > print join("\n",@main::sym),"\n"; > } For that matter, you can set the values by munging the symbol table: use strict; my $name = 'foo'; $::{$name} = [1,2,3]; # LHS is a glob print "@{ $::{$name} }\n"; no strict 'vars'; print "@foo\n"; But why use the symbol table at all? That's more dangerous than using a regular hash, and more awkward than using the symbolic references. -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]