in reply to Create an array with another variable
This is a fairly classic design pattern in Perl. As belg4mit said, use a hash;
my @array1; my @array2; my %arrayhash=( array1=>\@array1, array2=>\@array2, );
The above style is useful if you want to both be able to access the appropriate array by name and you directly want to modify the array without going through the hash. If you dont need the double access option then the shorter
my %arrayhash=( array1=>[], array2=>[], );
may be preferable. Incidentally it may help you to learn how to interact with the array once it is in the hash:
push @{$arrayhash{$name}},$value; $arrayhash{$name}->[$index]=$value; foreach my $item (@{$arrayhash{$name}}) { ... } foreach my $index (0.. $#{$arrayhash{$name}}) { ... }
References quick reference is probably something you should keep handy until you are comfortable with the various forms of dereferencing in perl.
|
|---|