From: "Airman" <[EMAIL PROTECTED]>
> Is there any special way to do row/col (two dimensional) based
> associative arrays?
> 
> Something like:
> 
> $array{1.1}="line one column one";
> $array{1.2}="line one column two";
> 
> or
> 
> @names(Bob,John,Jeff);
> @info=(Age,Zip,Phone);
> 
> $data{Bob.Age}=23;
> 
> foreach $entry (@names) {
>   print "$data{$entry.Age}\n";
> }
> 
> I guess in perl code maybe this would work???

There are actually three ways. Either you could have a hash of 
hashes:

        $array{Bob}{Age} = 23;

or you could use an ordinary hash and use some separator between the 
key and subkey.

        $array{"Bob|Age"} = 23;

or (which is actually the same thing as solution 2 use a comma:

        $array{Bob,Age} = 23;

this last option is equivalent to
        $array{"Bob".$;."Age"} = 23;
and $; is set to some character that's very unlikely to appear in 
your text.

Which of the options to use is up to you, the 2nd and 3rd should be a 
little less memory consuming, but it will be hard (and slow) to 
display eg. everything you know about Bob. In the first case it'd be

        foreach my $key (keys %{$array{Bob}}) {
                print "$key => $array{Bob}{$key}\n"
        }

while in the third you'd have to loop over the whole hash with 
something like:

        foreach my $key (keys %array) {
                next unless $key =~ /^Bob$;(.*)$/;
                print "$1 => $array{$key}\n";
        }

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to