Background
I have these four lines of code that I am trying to extract into one function:
my @firstList = split /\s+/, $doubleArray{A_I}{B_I};
@firstList = shuffle(@firstList);
my @secondList = split /\s+/, $doubleArray{A_I}{C_I};
@secondList = shuffle(@secondList);
Since the only functional difference is the second index of the two dimensional array , I wanted to make it so that the second index ("B_I" and "C_I") are passed into a function.
Proposed solution
In other words I want to make a function like the one below:
my funkyFunc($){
my $index = shift;
my @list = split /\s+/, $doubleArray{A_I}{$index};
@list = shuffle(@list);
return @list;
}
I would intend to use it as such:
my @firstList = funkyFunc("B_I");
my @secondList = funkyFunc("C_I");
However, I'm unsure as to how perl would interpret "B_I"
or "C_I"
, or likewise B_I
and C_I
. Because of this complexity, I wanted to know...
Question
Is there a way in perl to pass in the name of an array index?