The Ghost
Jul 8 2005, 06:47 PM
i want to do this:
@arraynames = ( 'ernie', 'bert', 'bbird');
foreach $name (@arraynames) {
push @$name, $someValue;
}
so I have an array @ernie, another array @bert, etc...
so how?
Thanks!
Charles K. Clarkson
Jul 8 2005, 07:09 PM
The Ghost <mailto:[Email Removed]> wrote:
: i want to do this:
:
: @arraynames = ( 'ernie', 'bert', 'bbird');
:
: foreach $name (@arraynames) {
: push @$name, $someValue;
: }
: so I have an array @ernie, another array @bert, etc...
:
Make the array names keys in a hash.
my @fields = ( 'ernie', 'bert', 'bbird');
my %config;
foreach my $name ( @fields ) {
push @{ $config{ $name } }, $some_value;
}
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
John W. Krahn
Jul 8 2005, 08:01 PM
The Ghost wrote:
QUOTE |
i want to do this:
@arraynames = ( 'ernie', 'bert', 'bbird');
foreach $name (@arraynames) { push @$name, $someValue; } so I have an array @ernie, another array @bert, etc...
so how?
|
Something like this:
my %arraynames = ( ernie => [], bert => [], bbird => [] );
foreach my $name ( keys %arraynames ) {
push @{ $arraynames{ $name } }, $someValue;
}
John
--
use Perl;
program
fulfillment
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.