set array name dynamically

Hi,

I am trying to name a set of arrays dynamically named as @array_$i (The $i will mean that I obtain a set of arrays called:
@array_1
@array_2
@array_3 etc.

i tried various methods like

@array_$i
@{array_$i}
etc.

any ways to do this

Thanks

Not sure what shell and OS you're using, but I'll assume bash considering your array notation.

The following works in bash on Linux and AIX:

$ array_1[0]=0
$ array_1[1]=1
$ array_1[2]=2
$ array_2[0]=3
$ array_2[1]=4
$ array_2[2]=5
$ for arrNum in `seq 1 2`
> do
> for arrDim in `seq 0 2`
> do
> echo "array_${arrNum}[${arrDim}] = $( eval echo \${array_${arrNum}[${arrDim}]} )"
> done
> done
array_1[0] = 0
array_1[1] = 1
array_1[2] = 2
array_2[0] = 3
array_2[1] = 4
array_2[2] = 5
$

Sorry, i forgot to say that i am looking for perl.

Let me explain the problem once again. Need to set the variable name when assigning the data.

for example, in my program i am trying to put something like this

foreach(@i){
@array_$i = /something/;
}

intention is
@array_1=/something/;
@array_2=/something/;
etc

Sorry, don't know what I was thinking. Bash doesn't even notate arrays starting with an '@'.

Anyhow, the easiest way in perl is to use hashes (associative arrays):

#!/usr/bin/perl

@i = qw(one two three);
$j = 1;

foreach (@i) {
  $hash{$_} = "\$hash{$_} = $j";
  $j++;
}

print "$hash{one}\n";
print "$hash{two}\n";
print "$hash{three}\n";

Yep, use a hash. Dynamic variable names in perl is possible using soft references but you shouldn't do that as it can lead to very buggy code. Use a hash.