Basically I think you know what I'm trying to do,
By the way, I took the code you posted and I'm trying to compile it right now to no avail, I'm getting errors, is it straight c or c++, I named the file test.c and test.cpp, cpp gave less errors though. I have
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
Should I get a later version?
I had a really hard time trying to update gcc the first time I tried about 6 months ago, but I'm a lot more savy with the teminal now even though I've still got a ways to go.
So about what I'm trying to do, as easily as I can lay it out I will explain furthur:
Lets say I have 10 arrays. They are char types. Each of the 10 arrays I will reffer to as a table.
I have 1 int type array which has 10 sets of 7 digit numbers.
int table_names[10];
table_names[0]=1234567;
table_names[1]=1234568;
table_names[2]=1234569;
table_names[3]=1234570;
table_names[4]=1234571;
table_names[5]=1234572;
table_names[6]=1234573;
table_names[7]=1234574;
table_names[8]=1234575;
table_names[9]=1234576;
table_names[10]=1234577;
Each of the 7 digit numbers in the array, is 'Inside' of the name of one of the ten tables.
The 10 tables are called out like the following example of a single table:
char table_1234567[20];
table_1234567['One']='TestValue';
I have each of my ten tables really simple like that example so while I'm trying to get it working I don't get confused.
Now that I have a random number between 1 and 10 (for the benifit of the examples I'll say 10 though I said 24 before) I select the random table Id from the table_names array.
With the random table Id in hand, I combine it with the string "table_" so I end up with:
table_1234567
Now that I have this value in a string called "tableName"
How can I access the table_1234567['One'] value using the tableName????
Now do you see what I mean? I'm really terrible at explaining things so I hope you've been able to bear with me.
I tried tableName['One'] but it prints out "(Null)".
But if I print the tableName I get the name of the array I'm trying to access. So what modification could I make to get the access to the table?
Thank You!!!!!!!
Hey, after this do you want me to help you on any perl code? I'm really great for perl!
=> is used to assign the left name which is called the 'key' in perl to the right name the 'value' in the 'hash'. Hashes are a special feature of perl. And quite unique to perl. Although I think python and about 5 other langs also support them. Hashes are also reffered to as "associative Arrays", which I read that c / c++ support too.
array['One']='two'; is the c equivilant I guess.
In perl it is
$array{'One'}='two';
Or
%array{
'One'=>'two',
'Two'=>'Three'
}
print "$array{'Two'}";
# Output: Three
The % starts the hash, and is usually used to create the majority of the hash items at once.
Rather than adding each key to the hash one by one:
$array{'One'}='two';
$array{'Two'}='three';
.. and so on
then you can easily loop through the hash,
foreach $key (keys %array){
print "$key - $array{$key}: ";
}
# output: One - two: Two - three:
I actually used to be a moderator at the uh, perl guru forums. I still have status but don't post anymore since everyone thinks I'm an idiot there. There's a bunch of those double posters there or whatever. You know the ones, you'll answer someones question then the other guy posts after you and complains that your code is un-efficient and to use his instead.
A lot of people from there also post here too. Since perlguru.com is pretty much all perl newbies with perl questions. Smart folks there though.
Ok Mate, thanks again, I keep checking this thing from time to time.
You could ask me a favor anytime. I can do flash a little here an there, well I have flash5 so I could do some stuff you may like with it, and I am really good at perl & javascript. If you think about it, perl + java is really close to c.
Ok, I'm going back to work,
Tony