1

I would like to create an array in Perl that will have for name the values of two variables and, one of the two variables will have a value that is read from a file.

In the simplified case, how can I create an array with name CCP when P and CC are two separate variables?

So far I have joined the two using:

my $body='CC';
my $letter='P';
my $joined=$body . "$venue";

but I would like to actually create an array with name @CCP. The idea is that I will read different letters from a data file and then create the arrays that will have names given by joining 'CC' to the letters read from file.

g_puffo
  • 613
  • 3
  • 11
  • 21

1 Answers1

9

You really don't want to do that. How will you know what the array is called when you need to access it?

Use a hash, like this

my %data;

my $body   = 'CC';
my $letter = 'P';

$data{"$body$letter"} = [];
Borodin
  • 126,100
  • 9
  • 70
  • 144