Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Join perl function to create variables

Tags:

perl

I am trying to do some thing like this:

my @Amode=('1','2','3');
my @Bmode=('1','2','3');
my @Cmode=('1','2','3');
my @Atemp=('1','2','3');
my @Btemp=('1','2','3');
my @Ctemp=('1','2','3');

my @mode=('A','B','C');
foreach (@mode) {
    my $newmode = join("",$_,mode);
    my $newtemp = join("",$_,temp);
}

I want to access the @Amode information through $newmode. Is this possible?

like image 868
user2829 Avatar asked Mar 18 '26 21:03

user2829


1 Answers

I see what you are trying to do there, but honestly I think you are making it more convoluted than it needs to be.

Why not use hashes?

my $modes = {
   'A' => [1,2,3],
   'B' => [1,2,3],
   'C' => [1,2,3],
};
foreach my $mode (keys %$modes){
    ... do something with $modes->{$mode};
}
like image 185
liamgriffiths Avatar answered Mar 20 '26 20:03

liamgriffiths