Help - Search - Member List - Calendar
Full Version: array names
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
The Ghost
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
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
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


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.