Thanks all for the replies.

My understanding is that two dimentional objects are usefull when $key1
(1 row) represents an unique identifier applied to $key2 (1 column) to
'point' to one piece of data (cell), if we were looking at a two
dimensional object (flat spreadsheet).

What I am looking for (and I think it was hinted in a couple emails) is
a way to store 2 pieces of data that both have the same key.  This can
be accomplished a number of ways, I guess it comes down to me wondering
which is the 'perl' way.  And if you cant tell, I am a new perl convert.
Some examples of what I mean:

my %data1_hash; my %data2_hash; my %unique_hash; my %my_hash;

my $identifier = 'unique';
my $data1 = 'a';
my $data2 = '2';

# 2 hashes
$data1_hash{$unique} = $data1;
$data2_hash($unique) = $data2;

# joined data with common delimeter, need to split out when want to
access $key1, $key2
$unique_hash($unique) = join('|', $data1, $data2);

# What I was tring to do.  Hoping there was an easy way to pull out both
$unique and $data1
# via some 'keys' call.  I guess this could be done with a join and
split, was wondering if there
# was another way.
$my_hash($unique, $key1) = $key2

foreach $key (keys(%my_hash)) {
  my ($value1, value2) = // split $key

Thanks,
Jason

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Don
VanSyckel
Sent: Wednesday, December 29, 2004 2:48 PM
To: [email protected]
Subject: Re: Hash with multiple keys?


The hash you listed has one key comprised to the values of two 
variables.  I believe you meant to use

$hash{$key1}{$key2} = $data;
...
forash $key1 (sort keys %hash)
{  foreach $key2 (sort keys %{$hash{$key1}})
    {  print "key1 = $key1\tkey2 = $key2\n";
    }
}

Don


Allison, Jason (JALLISON) wrote:
> Sorry for the horribly lame question, but I am not having any luck
> finding an answer, probably because I don't know how to phrase the 
> question properly.
> 
> When I have a hash defined by multiple keys, how can I pull both keys 
> out?
> 
> $hash{$key1, $key2} = $data;
> ...
> foreach $key (sort(keys(%hash))) {
>   # here ??
>   my ($key1, $key2) = split(/ /, $key, 2);
> }
> 
> Thanks a bunch,
> Jason
> 
> 
> ----------------------------------------------------------------------
> --
> 
> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to