Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays

Status
Not open for further replies.

ErichTheWebGuy

Programmer
Jul 17, 2002
9
US
I have several arrays that are named like this:
Code:
@array_1
@array_2
@array_3
etc..

I want to call upon their data like this:
Code:
@array_$variable[0]
but its not working... anyone know how I can get this to work?
 
I think it's something like

$array_1[0]

Does that help?
tgus

____________________________
Families can be together forever...
 
Thanks for your reply. I should have been more clear. What I need to do is loop through the arrays and extract their data and parse it for output. So, I wanted to do something like this:

Code:
@array_1='something','something else','more stuff';
@array 2='still more stuff','lotsa stuff','i hate stuff';
# etc... like that until array 15

sub whatever {
 $current=1;
 $upperLimit=15;
 
 if($current ne $upperLimit) {
  print @array_$current[0];
  print @array_$current[1];
  &whatever;
 }
}

But, it doesn't recognize $current and insert that where it should...
 
You need to eval the variable name that you assemble in a string
Code:
$data = eval '$array_'.$variable.'[0]';
# Or
$data = eval "\$array_$variable\[0]";

Take a look at this thread, too.

thread219-320997

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top