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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hash Table Question 1

Status
Not open for further replies.

javalsu

Programmer
Jan 11, 2007
5
US
Last time I posted you guys were really helpful, so here I go again.

What does it mean when a hash table seems to have two key elements.

for example

my %htable

htable{"n", "g"} = 100

Thanks in advance
 
You haven't posted valid code there.

The usual reason for referencing multiple keys of a hash is to set them at the same time, using a "hash slice". e.g.:
Code:
@htable{'n', 'g'} = (100,200);
So now the value of $htable{n} is 100 and $htable{g} is 200.
 
Hi javalsu

Your code (which I think should look like this)

my %htable;

$htable{"n", "g"} = 100;

It's an old fashioned, but still valid, way of treating a hash as if it is multidensional.

You could use this method to store values for all of the squares in a crossword puzzle for instance.

$row=1;
$col=1; $xwordgrid{$row,$col}='T';
$col=2; $xwordgrid{$row,$col}='E';
$col=3; $xwordgrid{$row,$col}='K';
$col=4; $xwordgrid{$row,$col}='T';
$col=5; $xwordgrid{$row,$col}='I';
$col=6; $xwordgrid{$row,$col}='P';
$col=7; $xwordgrid{$row,$col}='S';

You could then print out the crossword grid using a couple of loops.

It's more usual now to use nested hashes and things, but they're a bit clever for me.

Mike

The options are: fast, cheap and right - pick any two. [orientalbow] & [anakin]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Thanks, after looking at it looks like it is a multidimensional hash table.

Now I just have to implement a multidimensional hashtable in vb.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top