2

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?

1
  • 2
    You're sort of mixing two metaphors. Symbolic references can be manipulated but not in terms of lexical variables (my variables). And for what you're doing, it's the wrong way anyway. Using symbolic references as a poor-man's real refs opens up a can of worms... no... a refuse dumpster full of worms. Save symbolic refs for Exporter, Memoize, and other "magic" code. Commented Aug 4, 2011 at 22:11

2 Answers 2

6

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};
}
Sign up to request clarification or add additional context in comments.

Comments

4

You can't string together variable names, but you can make hash keys and access them.

E.g.

my %data = ( "A" => \@Amode, "B" => \@Bmode, "C" => \@Cmode );
my @mode = ("A", "B", "C");

for (@mode) {
    print @{$data{$_}};
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.