* Kenton Brede <[EMAIL PROTECTED]> [2006-10-06T11:38:49] > I've done some searching and can't find an answer to this. I'd like > to use a scalar variable in an array name. Something like "@$scalar" > I've tried different permutations like "[EMAIL PROTECTED]", "@"$scalar"" > "@\$scalar" and none of them work.
What you're talking about is a symbolic reference. The canonical reference for why /not/ to do this is here: http://perl.plover.com/varvarname.html > my $first_arg = "$ARGV[0]"; > my @list = ("all", "rhel"); > my @rhel = ("server1", "server3", "server4"); > my @all = ("server2", "server5", server7"); > > foreach my $list_name (@list) { > if ( $list_name eq $first_arg ) { > print "@$first_arg"; > } > } Use a hash instead: my $first_arg = $ARGV[0]; my %group = ( rhel => [ 'server1', 'server3', 'server4' ], all => [ 'server2', 'server5', 'server7' ], ); my @servers = @{ $group{ $first_arg } }; print "@servers"; -- rjbs -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>